Browse Source

Completed the JS localization API document

pull/5771/head
Halil İbrahim Kalkan 6 years ago
parent
commit
b10a8d3c1f
  1. 103
      docs/en/UI/AspNetCore/JavaScript-API/Localization.md
  2. 4
      docs/en/docs-nav.json

103
docs/en/UI/AspNetCore/JavaScript-API/Localization.md

@ -26,9 +26,15 @@ var str = abp.localization.localize('HelloWorld', 'Test');
`HelloWorld` is the text to localize, where `Test` is the localization resource name here.
### Fallback Logic
If given texts was not localized, localization method returns the given key as the localization result.
### Default Localization Resource
If you don't specify the localization resource name, it uses the **default localization resource** defined on the `AbpLocalizationOptions` (see the *Default Resource* section above). Example:
If you don't specify the localization resource name, it uses the **default localization resource** defined on the `AbpLocalizationOptions` (see the [localization document](../../../Localization.md)).
**Example: Using the default localization resource**
````js
var str = abp.localization.localize('HelloWorld'); //uses the default resource
@ -39,8 +45,99 @@ var str = abp.localization.localize('HelloWorld'); //uses the default resource
If your localized string contains arguments, like `Hello {0}, welcome!`, you can pass arguments to the localization methods. Examples:
````js
var str1 = abp.localization.getResource('Test')('HelloWelcomeMessage', 'John');
var testSource = abp.localization.getResource('Test');
var str1 = testSource('HelloWelcomeMessage', 'John');
var str2 = abp.localization.localize('HelloWelcomeMessage', 'Test', 'John');
````
Assuming the `HelloWelcomeMessage` is localized as `Hello {0}, welcome!`, both of the samples above produce the output `Hello John, welcome!`.
Assuming the `HelloWelcomeMessage` is localized as `Hello {0}, welcome!`, both of the samples above produce the output `Hello John, welcome!`.
## Other Properties & Methods
### abp.localization.values
`abp.localization.values` property stores all the localization resources, keys and their values.
### abp.localization.isLocalized
Returns a boolean indicating that if the given text was localized or not.
**Example**
````js
abp.localization.isLocalized('ProductName', 'MyResource');
````
Returns `true` if the `ProductName` text was localized for the `MyResource` resource. Otherwise, returns `false`. You can leave the resource name empty to use the default localization resource.
### abp.localization.defaultResourceName
`abp.localization.defaultResourceName` can be set to change the default localization resource. You normally don't set this since the ABP Framework automatically sets is based on the server side configuration.
### abp.localization.currentCulture
`abp.localization.currentCulture` returns an object to get information about the **currently selected language**.
An example value of this object is shown below:
````js
{
"displayName": "English",
"englishName": "English",
"threeLetterIsoLanguageName": "eng",
"twoLetterIsoLanguageName": "en",
"isRightToLeft": false,
"cultureName": "en",
"name": "en",
"nativeName": "English",
"dateTimeFormat": {
"calendarAlgorithmType": "SolarCalendar",
"dateTimeFormatLong": "dddd, MMMM d, yyyy",
"shortDatePattern": "M/d/yyyy",
"fullDateTimePattern": "dddd, MMMM d, yyyy h:mm:ss tt",
"dateSeparator": "/",
"shortTimePattern": "h:mm tt",
"longTimePattern": "h:mm:ss tt"
}
}
````
### abp.localization.languages
Used to get list of all **available languages** in the application. An example value of this object is shown below:
````js
[
{
"cultureName": "en",
"uiCultureName": "en",
"displayName": "English",
"flagIcon": null
},
{
"cultureName": "fr",
"uiCultureName": "fr",
"displayName": "Français",
"flagIcon": null
},
{
"cultureName": "pt-BR",
"uiCultureName": "pt-BR",
"displayName": "Português",
"flagIcon": null
},
{
"cultureName": "tr",
"uiCultureName": "tr",
"displayName": "Türkçe",
"flagIcon": null
},
{
"cultureName": "zh-Hans",
"uiCultureName": "zh-Hans",
"displayName": "简体中文",
"flagIcon": null
}
]
````

4
docs/en/docs-nav.json

@ -447,6 +447,10 @@
"text": "Overall",
"path": "UI/AspNetCore/JavaScript-API/Index.md"
},
{
"text": "Localization",
"path": "UI/AspNetCore/JavaScript-API/Localization.md"
},
{
"text": "AJAX",
"path": "UI/AspNetCore/JavaScript-API/Ajax.md"

Loading…
Cancel
Save