mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Adding type defs for y18n (#35050)
This commit is contained in:
parent
5de1470697
commit
a9cb5fa8b8
60
types/y18n/index.d.ts
vendored
Normal file
60
types/y18n/index.d.ts
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
// Type definitions for y18n 4.0
|
||||
// Project: https://github.com/yargs/y18n
|
||||
// Definitions by: Adam Zerella <https://github.com/adamzerella>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
interface Config {
|
||||
/**
|
||||
* The locale directory, default ./locales.
|
||||
*/
|
||||
directory: string;
|
||||
/**
|
||||
* Should newly observed strings be updated in file, default true.
|
||||
*/
|
||||
updateFiles: boolean;
|
||||
/**
|
||||
* What locale should be used.
|
||||
*/
|
||||
locale: string;
|
||||
/**
|
||||
* Should fallback to a language-only file (e.g. en.json) be allowed
|
||||
* if a file matching the locale does not exist (e.g. en_US.json), default true.
|
||||
*/
|
||||
fallbackToLanguage: boolean;
|
||||
}
|
||||
|
||||
declare class Y18N {
|
||||
/**
|
||||
* Create an instance of y18n with the config provided
|
||||
*/
|
||||
constructor(config?: Config)
|
||||
|
||||
/**
|
||||
* Print a localized string, %s will be replaced with args.
|
||||
*/
|
||||
__(str: string, arg1?: string, arg2?: string, arg3?: string): string;
|
||||
|
||||
/**
|
||||
* Print a localized string with appropriate pluralization.
|
||||
* If %d is provided in the string, the count will replace this placeholder.
|
||||
*/
|
||||
__n(singularString: string, pluralString: string, count: number, arg1?: string, arg2?: string, arg3?: string): string;
|
||||
|
||||
/**
|
||||
* Set the current locale being used.
|
||||
*/
|
||||
setLocale(str: string): void;
|
||||
|
||||
/**
|
||||
* What locale is currently being used?
|
||||
*/
|
||||
getLocale(): string;
|
||||
|
||||
/**
|
||||
* Update the current locale with the key value pairs in obj.
|
||||
*/
|
||||
updateLocale(obj: object): void;
|
||||
}
|
||||
|
||||
export = Y18N;
|
||||
25
types/y18n/tsconfig.json
Normal file
25
types/y18n/tsconfig.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [
|
||||
|
||||
],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"y18n-tests.ts"
|
||||
]
|
||||
}
|
||||
3
types/y18n/tslint.json
Normal file
3
types/y18n/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
21
types/y18n/y18n-tests.ts
Normal file
21
types/y18n/y18n-tests.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import y18n = require("y18n");
|
||||
|
||||
// Testing custom config
|
||||
new y18n({
|
||||
directory: '../locales',
|
||||
updateFiles: false,
|
||||
locale: 'en-AU',
|
||||
fallbackToLanguage: false
|
||||
});
|
||||
|
||||
const Y18N = new y18n();
|
||||
|
||||
Y18N.__(`my awesome string: foo`);
|
||||
|
||||
Y18N.__n('one fish %s', '%d fishes %s', 2, 'foo');
|
||||
|
||||
Y18N.setLocale('en-US');
|
||||
|
||||
Y18N.getLocale();
|
||||
|
||||
Y18N.updateLocale({});
|
||||
Loading…
Reference in New Issue
Block a user