Skip to content

Commit

Permalink
Merge pull request #66 from Kurounin/typings
Browse files Browse the repository at this point in the history
Added typings
  • Loading branch information
StephanHoyer authored Oct 24, 2018
2 parents 9bf8af8 + f6c0520 commit 0a9c063
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
55 changes: 55 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Type definitions for translate.js 1.2.1
// Project: https://github.com/StephanHoyer/translate.js#readme
// Definitions by: Kurounin <https://github.com/Kurounin>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8

interface Params {
[key: string]: string;
}

export interface Messages {
[key: string]: string | Messages;
[key: number]: string | Messages;
}

type translateFunc1<T> = (key: string) => T;
type translateFunc2<T> = (key: string, subKey: number | string) => T;
type translateFunc3<T> = (key: string, params: Params) => T;
type translateFunc4<T> = (key: string, subKey: number | string, params: Params) => T;
type translateFunc5<T> = (key: string, params: Params, subKey: number | string) => T;

export interface Options {
debug?: boolean;
array?: boolean;
resolveAliases?: boolean;
pluralize?: (n: number, translationKey: string) => number | string;
useKeyForMissingTranslation?: boolean;
}

export interface ArrayOptions extends Options {
array: true;
}

export type Translate<T extends ArrayOptions | Options> = {
keys: Messages;
arr: translateFunc1<any[]> & translateFunc2<any[]> & translateFunc3<any[]> & translateFunc4<any[]> & translateFunc5<any[]>;
opts: T;
}
& translateFunc1<T extends ArrayOptions ? any[] : string>
& translateFunc2<T extends ArrayOptions ? any[] : string>
& translateFunc3<T extends ArrayOptions ? any[] : string>
& translateFunc4<T extends ArrayOptions ? any[] : string>
& translateFunc5<T extends ArrayOptions ? any[] : string>;

type translateJsFunc1 = (messages: Messages) => Translate<Options>;
type translateJsFunc2 = (messages: Messages, options: ArrayOptions) => Translate<ArrayOptions>;
type translateJsFunc3 = (messages: Messages, options: Options) => Translate<Options>;

type translateJs = {
resolveAliases: (messages: Messages) => Messages;
} & translateJsFunc1 & translateJsFunc2 & translateJsFunc3;

declare const translate: translateJs;

export default translate;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "translate.js",
"version": "1.2.0",
"version": "1.2.1",
"description": "Javascript micro library for translations (i18n) with support for placeholders and multiple plural forms.",
"devDependencies": {
"benchmark": "2.1.4",
Expand Down Expand Up @@ -38,6 +38,7 @@
},
"module": "index.js",
"main": "common.js",
"types": "index.d.ts",
"contributors": [
{
"name": "Stephan Hoyer",
Expand Down
19 changes: 19 additions & 0 deletions plurals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Type definitions for translate.js/plurals 1.2.1
// Project: https://github.com/StephanHoyer/translate.js#readme
// Definitions by: Kurounin <https://github.com/Kurounin>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8

type plural = (n: number, translationKey: string) => string;

export const plural_CS: plural;
export const plural_DA: plural;
export const plural_DE: plural;
export const plural_EN: plural;
export const plural_ES: plural;
export const plural_FR: plural;
export const plural_IS: plural;
export const plural_IT: plural;
export const plural_JA: plural;
export const plural_PT: plural;
export const plural_SE: plural;

0 comments on commit 0a9c063

Please sign in to comment.