mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-22 11:57:33 +08:00
Add type definitions for polyglot.js
This commit is contained in:
47
node-polyglot/node-polyglot-tests.ts
Normal file
47
node-polyglot/node-polyglot-tests.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import Polyglot = require("node-polyglot");
|
||||
|
||||
function instantiatePolyglot(): void {
|
||||
var polyglot = new Polyglot();
|
||||
var phrasedPolyglot = new Polyglot({phrases: {"hello": "Hello"}});
|
||||
var localePolyglot = new Polyglot({locale: "fr"});
|
||||
}
|
||||
|
||||
function translate(): void {
|
||||
var polyglot = new Polyglot();
|
||||
|
||||
polyglot.extend({
|
||||
"hello": "Hello",
|
||||
"hello_name": "Hola, %{name}.",
|
||||
"nav": {
|
||||
"sidebar": {
|
||||
"welcome": "Welcome"
|
||||
}
|
||||
},
|
||||
"num_cars": "%{smart_count} car |||| %{smart_count} cars"
|
||||
});
|
||||
|
||||
polyglot.t("hello");
|
||||
polyglot.t("hello_name");
|
||||
polyglot.t("nav.sidebar.welcome");
|
||||
polyglot.t("num_cars", {smart_count: 0});
|
||||
polyglot.t("num_cars", 0);
|
||||
polyglot.t("hello_name", {name: "Spike"});
|
||||
polyglot.t("i_like_to_write_in_language", {
|
||||
_: "I like to write in %{language}.",
|
||||
language: "Javascript"
|
||||
});
|
||||
|
||||
polyglot.replace({
|
||||
"hello": "hey",
|
||||
"nav": {
|
||||
"sidebar": {
|
||||
"welcome": "Greetings"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
polyglot.clear();
|
||||
|
||||
polyglot.locale("fr");
|
||||
polyglot.locale();
|
||||
}
|
||||
42
node-polyglot/node-polyglot.d.ts
vendored
Normal file
42
node-polyglot/node-polyglot.d.ts
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
// Type definitions for node-polyglot v0.4.1
|
||||
// Project: https://github.com/airbnb/polyglot.js
|
||||
// Definitions by: Tim Jackson-Kiely <https://github.com/timjk>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module "node-polyglot" {
|
||||
module Polyglot {
|
||||
interface InterpolationOptions {
|
||||
name?: string;
|
||||
smart_count?: number;
|
||||
_?: string;
|
||||
}
|
||||
|
||||
interface PolyglotOptions {
|
||||
phrases?: any;
|
||||
locale?: string;
|
||||
}
|
||||
}
|
||||
|
||||
class Polyglot {
|
||||
constructor(options?: Polyglot.PolyglotOptions);
|
||||
|
||||
extend(phrases: any): void;
|
||||
|
||||
t(phrase: string): string;
|
||||
|
||||
t(phrase: string, smartCount: number): string;
|
||||
|
||||
t(phrase: string, interpolationOptions: Polyglot.InterpolationOptions): string;
|
||||
|
||||
clear(): void;
|
||||
|
||||
replace(phrases: any): void;
|
||||
|
||||
locale(): string;
|
||||
|
||||
locale(locale: string): void;
|
||||
}
|
||||
|
||||
export = Polyglot;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user