@@ -39,32 +39,49 @@ type ExtractedVariables<T extends string> =
3939
4040type TranslationVariables < K extends string > = Record < ExtractedVariables < K > , string | number | TranslationVariableReplacementObject < string | number > >
4141
42+ export function translate < T extends string > ( app : string , text : T , placeholders ?: TranslationVariables < T > , options ?: TranslationOptions ) : string
43+ export function translate < T extends string > ( app : string , text : T , number ?: number , options ?: TranslationOptions ) : string
44+ /**
45+ * @inheritdoc
46+ * @deprecated This overload is deprecated either use placeholders or a number but not both
47+ */
48+ export function translate < T extends string > ( app : string , text : T , placeholders ?: TranslationVariables < T > , number ?: number , options ?: TranslationOptions ) : string
49+
4250/**
4351 * Translate a string
4452 *
45- * @param {string } app the id of the app for which to translate the string
46- * @param {string } text the string to translate
47- * @param {object } vars map of placeholder key to value
48- * @param {number } number to replace %n with
49- * @param {object } [options] options object
50- * @param {boolean } options.escape enable/disable auto escape of placeholders (by default enabled)
51- * @param {boolean } options.sanitize enable/disable sanitization (by default enabled)
52- *
53- * @return {string }
53+ * @param app the id of the app for which to translate the string
54+ * @param text the string to translate
55+ * @param placeholdersOrNumber map of placeholder key to value or a number replacing `%n`
56+ * @param optionsOrNumber the translation options or a number to replace `%n` with
57+ * @param options options object
58+ * @param options.escape enable/disable auto escape of placeholders (by default enabled)
59+ * @param options.sanitize enable/disable sanitization (by default enabled)
5460 */
5561export function translate < T extends string > (
5662 app : string ,
5763 text : T ,
58- vars ?: TranslationVariables < T > ,
59- number ?: number ,
64+ placeholdersOrNumber ?: TranslationVariables < T > | number ,
65+ optionsOrNumber ?: number | TranslationOptions ,
6066 options ?: TranslationOptions ,
6167) : string {
68+ const vars = typeof placeholdersOrNumber === 'object' ? placeholdersOrNumber : undefined
69+ const number = typeof optionsOrNumber === 'number' ? optionsOrNumber : ( typeof placeholdersOrNumber === 'number' ? placeholdersOrNumber : undefined )
70+
6271 const allOptions = {
6372 // defaults
6473 escape : true ,
6574 sanitize : true ,
6675 // overwrite with user config
67- ...( options || { } ) ,
76+ ...(
77+ typeof options === 'object'
78+ ? options
79+ : (
80+ typeof optionsOrNumber === 'object'
81+ ? optionsOrNumber
82+ : { }
83+ )
84+ ) ,
6885 }
6986
7087 const identity = < T , > ( value : T ) : T => value
0 commit comments