Add counterpart

This commit is contained in:
Santiago Doldan
2017-08-23 23:29:59 -03:00
parent 96cffadf50
commit c2c9b9f7c0
4 changed files with 84 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import * as counterpart from 'counterpart';
counterpart('translation.to.be.used');
counterpart(['translation', 'to', 'be', 'used']);
counterpart.setSeparator('*');
counterpart.onTranslationNotFound((locale: string, key: string, fallback: string, scope: string) => {});
counterpart.offTranslationNotFound((locale: string, key: string, fallback: string, scope: string) => {});
counterpart.setMissingEntryGenerator((value: string) => {});
counterpart.setLocale('es');
counterpart.getLocale();
counterpart.onLocaleChange((newLocale: string, oldLocale: string) => {});
counterpart.offLocaleChange((newLocale: string, oldLocale: string) => {});
counterpart.setFallbackLocale('es');
counterpart.registerTranslations('es', { hello: 'Hola' });
counterpart.registerInterpolations({ library: 'Counterpart' });
counterpart.setKeyTransformer((value: string, options: object) => {
return value.toUpperCase();
});
counterpart.localize(new Date(), { format: 'short' });

32
types/counterpart/index.d.ts vendored Normal file
View File

@@ -0,0 +1,32 @@
// Type definitions for counterpart 0.18
// Project: https://github.com/martinandert/counterpart
// Definitions by: santiagodoldan <https://github.com/santiagodoldan>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
type NotFoundHandler = (locale: string, key: string, fallback: string, scope: string) => void;
type LocaleChangeHandler = (newLocale: string, oldLocale: string) => void;
interface Counterpart {
(key: string|string[], options?: object): string;
setSeparator(value: string): string;
onTranslationNotFound(callback: NotFoundHandler): void;
offTranslationNotFound(callback: NotFoundHandler): void;
setMissingEntryGenerator(callback: (value: string) => void): void;
getLocale(): string;
setLocale(value: string): string;
onLocaleChange(callback: LocaleChangeHandler): void;
offLocaleChange(callback: LocaleChangeHandler): void;
setFallbackLocale(value: string|string[]): void;
registerTranslations(locale: string, data: object): void;
registerInterpolations(data: object): void;
setKeyTransformer(callback: (value: string, options: object) => string): string;
localize(date: Date, options: object): string;
Instance: Counterpart;
Translator: Counterpart;
}
declare var counterpart: Counterpart;
export = counterpart;

View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"counterpart-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }