|
@@ -91,6 +91,11 @@ interface IOptions {
|
|
*/
|
|
*/
|
|
pluralForms?: string;
|
|
pluralForms?: string;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * The string prefix to add to localized strings.
|
|
|
|
+ */
|
|
|
|
+ stringsPrefix?: string;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Plural form function.
|
|
* Plural form function.
|
|
*/
|
|
*/
|
|
@@ -132,7 +137,8 @@ class Gettext {
|
|
pluralFunc: function (n: number) {
|
|
pluralFunc: function (n: number) {
|
|
return { nplurals: 2, plural: n != 1 ? 1 : 0 };
|
|
return { nplurals: 2, plural: n != 1 ? 1 : 0 };
|
|
},
|
|
},
|
|
- contextDelimiter: String.fromCharCode(4) // \u0004
|
|
|
|
|
|
+ contextDelimiter: String.fromCharCode(4), // \u0004
|
|
|
|
+ stringsPrefix: ''
|
|
};
|
|
};
|
|
|
|
|
|
// Ensure the correct separator is used
|
|
// Ensure the correct separator is used
|
|
@@ -140,6 +146,7 @@ class Gettext {
|
|
this._domain = options.domain || this._defaults.domain;
|
|
this._domain = options.domain || this._defaults.domain;
|
|
this._contextDelimiter =
|
|
this._contextDelimiter =
|
|
options.contextDelimiter || this._defaults.contextDelimiter;
|
|
options.contextDelimiter || this._defaults.contextDelimiter;
|
|
|
|
+ this._stringsPrefix = options.stringsPrefix || this._defaults.stringsPrefix;
|
|
this._pluralFuncs = {};
|
|
this._pluralFuncs = {};
|
|
this._dictionary = {};
|
|
this._dictionary = {};
|
|
this._pluralForms = {};
|
|
this._pluralForms = {};
|
|
@@ -208,6 +215,24 @@ class Gettext {
|
|
return this._domain;
|
|
return this._domain;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Set current strings prefix.
|
|
|
|
+ *
|
|
|
|
+ * @param prefix - The string prefix to set.
|
|
|
|
+ */
|
|
|
|
+ setStringsPrefix(prefix: string): void {
|
|
|
|
+ this._stringsPrefix = prefix;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Get current strings prefix.
|
|
|
|
+ *
|
|
|
|
+ * @return The strings prefix.
|
|
|
|
+ */
|
|
|
|
+ getStringsPrefix(): string {
|
|
|
|
+ return this._stringsPrefix;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* `sprintf` equivalent, takes a string and some arguments to make a
|
|
* `sprintf` equivalent, takes a string and some arguments to make a
|
|
* computed string.
|
|
* computed string.
|
|
@@ -563,7 +588,10 @@ class Gettext {
|
|
): string {
|
|
): string {
|
|
// Singular is very easy, just pass dictionary message through strfmt
|
|
// Singular is very easy, just pass dictionary message through strfmt
|
|
if (!options.pluralForm)
|
|
if (!options.pluralForm)
|
|
- return Gettext.strfmt(this.removeContext(messages[0]), ...args);
|
|
|
|
|
|
+ return (
|
|
|
|
+ this._stringsPrefix +
|
|
|
|
+ Gettext.strfmt(this.removeContext(messages[0]), ...args)
|
|
|
|
+ );
|
|
|
|
|
|
let plural;
|
|
let plural;
|
|
|
|
|
|
@@ -591,9 +619,12 @@ class Gettext {
|
|
)
|
|
)
|
|
plural.plural = 0;
|
|
plural.plural = 0;
|
|
|
|
|
|
- return Gettext.strfmt(
|
|
|
|
- this.removeContext(messages[plural.plural]),
|
|
|
|
- ...[n].concat(args)
|
|
|
|
|
|
+ return (
|
|
|
|
+ this._stringsPrefix +
|
|
|
|
+ Gettext.strfmt(
|
|
|
|
+ this.removeContext(messages[plural.plural]),
|
|
|
|
+ ...[n].concat(args)
|
|
|
|
+ )
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -621,6 +652,7 @@ class Gettext {
|
|
this._dictionary[domain][locale] = messages;
|
|
this._dictionary[domain][locale] = messages;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private _stringsPrefix: string;
|
|
private _pluralForms: any;
|
|
private _pluralForms: any;
|
|
private _dictionary: any;
|
|
private _dictionary: any;
|
|
private _locale: string;
|
|
private _locale: string;
|