|
|
|
@ -72,8 +72,61 @@ var abp = abp || {}; |
|
|
|
/* LOCALIZATION ***********************************************/ |
|
|
|
|
|
|
|
abp.localization = abp.localization || {}; |
|
|
|
|
|
|
|
abp.localization.internal = abp.localization.internal || {}; |
|
|
|
abp.localization.values = abp.localization.values || {}; |
|
|
|
abp.localization.resources = abp.localization.resources || {}; |
|
|
|
|
|
|
|
abp.localization.internal.getResource = function (resourceName) { |
|
|
|
var resource = abp.localization.resources[resourceName]; |
|
|
|
if (resource) { |
|
|
|
return resource; |
|
|
|
} |
|
|
|
|
|
|
|
var legacySource = abp.localization.values[resourceName]; |
|
|
|
if (legacySource) { |
|
|
|
return { |
|
|
|
texts: abp.localization.values[resourceName], |
|
|
|
baseResources: [] |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
abp.log.warn('Could not find localization source: ' + resourceName); |
|
|
|
return null; |
|
|
|
}; |
|
|
|
|
|
|
|
abp.localization.internal.localize = function (key, sourceName) { |
|
|
|
var resource = abp.localization.internal.getResource(sourceName); |
|
|
|
if (!resource){ |
|
|
|
return { |
|
|
|
value: key, |
|
|
|
found: false |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
var value = resource.texts[key]; |
|
|
|
if (value === undefined) { |
|
|
|
for (var i = 0; i < resource.baseResources.length; i++){ |
|
|
|
var result = abp.localization.internal.localize(key, resource.baseResources[i]); |
|
|
|
if (result.found){ |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
value: key, |
|
|
|
found: false |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
var copiedArguments = Array.prototype.slice.call(arguments, 0); |
|
|
|
copiedArguments.splice(1, 1); |
|
|
|
copiedArguments[0] = value; |
|
|
|
|
|
|
|
return { |
|
|
|
value: abp.utils.formatString.apply(this, copiedArguments), |
|
|
|
found: true |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
abp.localization.localize = function (key, sourceName) { |
|
|
|
if (sourceName === '_') { //A convention to suppress the localization
|
|
|
|
@ -86,22 +139,7 @@ var abp = abp || {}; |
|
|
|
return key; |
|
|
|
} |
|
|
|
|
|
|
|
var source = abp.localization.values[sourceName]; |
|
|
|
if (!source) { |
|
|
|
abp.log.warn('Could not find localization source: ' + sourceName); |
|
|
|
return key; |
|
|
|
} |
|
|
|
|
|
|
|
var value = source[key]; |
|
|
|
if (value == undefined) { |
|
|
|
return key; |
|
|
|
} |
|
|
|
|
|
|
|
var copiedArguments = Array.prototype.slice.call(arguments, 0); |
|
|
|
copiedArguments.splice(1, 1); |
|
|
|
copiedArguments[0] = value; |
|
|
|
|
|
|
|
return abp.utils.formatString.apply(this, copiedArguments); |
|
|
|
return abp.localization.internal.localize(key, sourceName).value; |
|
|
|
}; |
|
|
|
|
|
|
|
abp.localization.isLocalized = function (key, sourceName) { |
|
|
|
@ -114,17 +152,7 @@ var abp = abp || {}; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
var source = abp.localization.values[sourceName]; |
|
|
|
if (!source) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
var value = source[key]; |
|
|
|
if (value === undefined) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
return abp.localization.internal.localize(key, sourceName).found; |
|
|
|
}; |
|
|
|
|
|
|
|
abp.localization.getResource = function (name) { |
|
|
|
@ -687,7 +715,7 @@ var abp = abp || {}; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Escape HTML to help prevent XSS attacks. |
|
|
|
* Escape HTML to help prevent XSS attacks. |
|
|
|
*/ |
|
|
|
abp.utils.htmlEscape = function (html) { |
|
|
|
return typeof html === 'string' ? html.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"') : html; |
|
|
|
@ -759,7 +787,7 @@ var abp = abp || {}; |
|
|
|
return toUtc(date); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/* FEATURES *************************************************/ |
|
|
|
|
|
|
|
abp.features = abp.features || {}; |
|
|
|
@ -774,7 +802,7 @@ var abp = abp || {}; |
|
|
|
abp.features.get = function (name) { |
|
|
|
return abp.features.values[name]; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/* GLOBAL FEATURES *************************************************/ |
|
|
|
|
|
|
|
abp.globalFeatures = abp.globalFeatures || {}; |
|
|
|
|