@brightspace-ui/intl
Advanced tools
Comparing version 3.20.0 to 3.20.1
@@ -8,20 +8,2 @@ import './PluralRules.js'; | ||
const characterMap = new Map([ | ||
['\'', 'apostrophe'], | ||
['&', 'ampersand'], | ||
['*', 'asterisk'], | ||
['\\', 'backslash'], | ||
[':', 'colon'], | ||
[',', 'comma'], | ||
['>', 'greaterThan'], | ||
['<', 'lessThan'], | ||
['#', 'numberSign'], | ||
['%', 'percentSign'], | ||
['|', 'pipe'], | ||
['?', 'questionMark'], | ||
['"', 'quotationMark'] | ||
]); | ||
const commonResources = new Map(); | ||
export let commonResourcesImportCount = 0; | ||
const getDisallowedTagsRegex = allowedTags => { | ||
@@ -90,13 +72,2 @@ const validTerminators = '([>\\s/]|$)'; | ||
localizeCharacter(char) { | ||
if (!characterMap.has(char)) { | ||
throw new Error(`localizeCharacter() does not support character: "${char}"`); | ||
} | ||
const value = this.localize(`intl-common:characters:${characterMap.get(char)}`); | ||
if (value.length === 0) { | ||
throw new Error('localizeCharacter() cannot be used unless loadCommon in localizeConfig is enabled'); | ||
} | ||
return value; | ||
} | ||
localizeHTML(name, replacements = {}) { | ||
@@ -161,17 +132,4 @@ | ||
const possibleLanguages = this._generatePossibleLanguages(config); | ||
if (config?.importFunc) { | ||
const resourcesPromise = this.getLocalizeResources(possibleLanguages, config); | ||
resourcesLoadedPromises.push(resourcesPromise); | ||
} | ||
if (config?.loadCommon) { | ||
resourcesLoadedPromises.push(this.getLocalizeResources(possibleLanguages, { | ||
importFunc: async(lang) => { | ||
if (commonResources.has(lang)) return commonResources.get(lang); | ||
const resources = (await import(`../lang/${lang}.js`)).default; | ||
commonResourcesImportCount++; | ||
commonResources.set(lang, resources); | ||
return resources; | ||
} | ||
})); | ||
} | ||
const resourcesPromise = this.getLocalizeResources(possibleLanguages, config); | ||
resourcesLoadedPromises.push(resourcesPromise); | ||
} | ||
@@ -178,0 +136,0 @@ return Promise.all(resourcesLoadedPromises); |
{ | ||
"name": "@brightspace-ui/intl", | ||
"version": "3.20.0", | ||
"version": "3.20.1", | ||
"description": "Internationalization APIs for number, date, time and file size formatting and parsing in D2L Brightspace.", | ||
@@ -14,3 +14,2 @@ "main": "lib/number.js", | ||
"files": [ | ||
"/lang", | ||
"/lib", | ||
@@ -17,0 +16,0 @@ "/helpers" |
@@ -8,3 +8,3 @@ # intl | ||
This library consists of APIs to format and parse numbers, dates, times and file sizes for use in D2L Brightspace. It also provides localization for common terms. | ||
This library consists of APIs to format and parse numbers, dates, times and file sizes for use in D2L Brightspace. | ||
@@ -32,6 +32,4 @@ > Looking for the older `d2l-intl` library? It's still here [in the `v2.x` branch](https://github.com/BrightspaceUI/intl/tree/v2.x). | ||
## Numbers | ||
## Number Formatting | ||
### Number Formatting | ||
Integer and decimal numbers can be formatted in the user's locale using `formatNumber`. Percentages can be formatted using `formatPercent`. Use the optional `options` parameter for rounding. | ||
@@ -72,3 +70,3 @@ | ||
### Number Parsing | ||
## Number Parsing | ||
@@ -83,6 +81,4 @@ The `parseNumber` method can be used to parse an integer or decimal number written in the user's locale. | ||
## Dates & Times | ||
## Date/Time Formatting | ||
### Date & Time Formatting | ||
Dates and times can be formatted in the user's locale using `formatDate`, `formatTime`, `formatDateTime`, and `formatRelativeDateTime`. | ||
@@ -194,3 +190,3 @@ | ||
### Date Parsing | ||
## Date Parsing | ||
@@ -208,3 +204,3 @@ To parse a date written in the user's locale, use `parseDate`: | ||
### Time Parsing | ||
## Time Parsing | ||
@@ -221,3 +217,3 @@ To parse a time written in the user's locale, use `parseTime`: | ||
### Date/Time Conversion based on user timezone | ||
## Date/Time Conversion based on user timezone | ||
@@ -386,37 +382,3 @@ To convert an object containing a UTC date to an object containing a local date corresponding to the `data-timezone` attribute: | ||
### Common Resources | ||
Some localization resources are common and shared across D2L applications. To use these resources, set the `loadCommon` option: | ||
```javascript | ||
import { Localize } from '@brightspace-ui/intl/lib/localize.js'; | ||
const localizer = new Localize({ | ||
loadCommon: true | ||
}); | ||
``` | ||
#### localizeCharacter | ||
The localized value of the following characters can be accessed using `localizeCharacter(char)`: | ||
* `'` (apostrophe) | ||
* `&` (ampersand) | ||
* `*` (asterisk) | ||
* `\` (backslash) | ||
* `:` (colon) | ||
* `,` (comma) | ||
* `>` (greater-than sign) | ||
* `<` (less-than sign) | ||
* `#` (number sign) | ||
* `%` (percent sign) | ||
* `|` (pipe) | ||
* `?` (question mark) | ||
* `"` (quotation mark) | ||
```javascript | ||
const value = localizer.localizeCharacter('&'); // -> 'ampersand' in en-US | ||
``` | ||
### `onResourcesChange` | ||
Provide an `onResourcesChange` callback function to perform tasks when the document language is changed and updated resources are available: | ||
@@ -423,0 +385,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98576
11
2253
412