Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#51208 [i18n] Add missing configuration opt…
Browse files Browse the repository at this point in the history
…ions by @martin-badin
  • Loading branch information
martin-badin authored Feb 28, 2021
1 parent d1530f6 commit a577916
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
36 changes: 23 additions & 13 deletions types/i18n/i18n-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,31 @@ i18n.configure({
// you may alter a site wide default locale
defaultLocale: 'de',

// will return translation from defaultLocale in case current locale doesn't provide it
retryInDefaultLocale: false,

// sets a custom cookie name to parse locale settings from - defaults to NULL
cookie: 'yourcookiename',

// sets a custom header name to read the language preference from - accept-language header by default
header: 'accept-language',

// query parameter to switch locale (ie. /home?lang=ch) - defaults to NULL
queryParameter: 'lang',

// where to store json files - defaults to './locales' relative to modules directory
directory: './mylocales',

// controll mode on directory creation - defaults to NULL which defaults to umask of process user. Setting has no effect on win.
// control mode on directory creation - defaults to NULL which defaults to umask of process user. Setting has no effect on win.
directoryPermissions: '755',

// watch for changes in json files to reload locale on updates - defaults to false
// watch for changes in JSON files to reload locale on updates - defaults to false
autoReload: true,

// whether to write new locale information to disk - defaults to true
updateFiles: false,

// sync locale information accros all files - defaults to false
// sync locale information across all files - defaults to false
syncFiles: false,

// what to use as the indentation unit - defaults to "\t"
Expand Down Expand Up @@ -101,20 +107,24 @@ i18n.configure({
preserveLegacyCase: true,

// Static translation catalog. Setting this option overrides `locales`
// tslint:disable:object-literal-key-quotes
staticCatalog: {
'en-US': {
'no': 'No',
'ok': 'Ok',
'yes': 'Yes'
no: 'No',
ok: 'Ok',
yes: 'Yes',
},
'nl-NL': {
'no': 'Nee',
'ok': 'Oké',
'yes': 'Ja'
}
}
// tslint:enable:object-literal-key-quotes
no: 'Nee',
ok: 'Oké',
yes: 'Ja',
},
},

// use mustache with customTags (https://www.npmjs.com/package/mustache#custom-delimiters) or disable mustache entirely
mustacheConfig: {
tags: ['{{', '}}'],
disable: false,
},
});

/**
Expand Down
29 changes: 28 additions & 1 deletion types/i18n/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Type definitions for i18n-node 0.12
// Type definitions for i18n-node 0.13
// Project: http://github.com/mashpie/i18n-node
// Definitions by: Maxime LUCE <https://github.com/SomaticIT>
// FindQ <https://github.com/FindQ>
// Martin Badin <https://github.com/martin-badin>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 4.1

Expand Down Expand Up @@ -31,12 +32,24 @@ declare namespace i18n {
*/
defaultLocale?: string;

/**
* Will return translation from defaultLocale in case current locale doesn't provide it
* @default false
*/
retryInDefaultLocale?: boolean;

/**
* Sets a custom cookie name to parse locale settings from
* @default null
*/
cookie?: string;

/**
* Sets a custom header name to read the language preference from - accept-language header by default
* @default 'accept-language'
*/
header?: string;

/**
* Query parameter to switch locale (ie. /home?lang=ch)
* @default null
Expand Down Expand Up @@ -150,6 +163,20 @@ declare namespace i18n {
* @since 0.10.0
*/
staticCatalog?: GlobalCatalog;

/**
* Use mustache with customTags (https://www.npmjs.com/package/mustache#custom-delimiters) or disable mustache entirely
*/
mustacheConfig?: {
/**
* @default ['{{', '}}']
*/
tags?: [string, string];
/**
* @default false
*/
disable?: boolean;
};
}
interface TranslateOptions {
phrase: string;
Expand Down

0 comments on commit a577916

Please sign in to comment.