intl-template 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/intl.js +13 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intl-template",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "l10n tagged template literals",
5
5
  "type": "module",
6
6
  "main": "dist/intl.js",
package/src/intl.js CHANGED
@@ -33,9 +33,20 @@ export function parseTemplate(templateString) {
33
33
  * Represents a Translation object that handles string translation based on locale and templates.
34
34
  */
35
35
  export class Translation {
36
- /** @type {"" | "react"} */
36
+ /** @type {"string" | "react"} */
37
37
  mode = "react"
38
38
 
39
+ /**
40
+ * The current locale for translation.
41
+ * @type {string}
42
+ **/
43
+ locale = ""
44
+
45
+ constructor(defaultLocale, mode = "react") {
46
+ this.mode = mode
47
+ this.locale = defaultLocale || globalThis?.navigator?.language || "en"
48
+ }
49
+
39
50
  /**
40
51
  * Templates object that stores the translation templates for each locale.
41
52
  * @type {Proxy}
@@ -134,4 +145,4 @@ const translation = new Translation()
134
145
 
135
146
  export default translation
136
147
 
137
- export const l10n = translation.translate.bind(null, globalThis?.navigator?.language);
148
+ export const l10n = translation.translate.bind(null, translation.locale);