@@ -2,23 +2,92 @@ import Gettext = require("gettext.js");
22
33const instance = Gettext ( ) ;
44
5- const json : Gettext . JsonData = {
6- "" : {
5+ {
6+ const messages = {
77 language : "fr" ,
88 "plural-forms" : "nplurals=2; plural=n>1;" ,
9- } ,
10- Welcome : "Bienvenue" ,
11- "There is %1 apple" : [
12- "Il y a %1 pomme" ,
13- "Il y a %1 pommes" ,
14- ] ,
15- } ;
16-
17- instance . loadJSON ( json , "messages" ) ;
18- instance . setLocale ( "fr" ) ;
19- if ( instance . ngettext ( "There is %1 apple" , "There are %1 apples" , 0 ) !== "Il y a 0 pomme" ) {
20- throw new Error ( "Failed test" ) ;
21- }
22- if ( instance . strfmt ( "There are %1 apples" , 0 ) !== "There are 0 apples" ) {
23- throw new Error ( "Failed test" ) ;
9+ } satisfies Gettext . JsonDataMessages ;
10+
11+ // $ExpectType Gettext
12+ instance
13+ . setMessages ( "domain" , "fr" , messages )
14+ . setMessages ( "domain" , "fr" , messages , "nplurals=2; plural=n>1;" ) ;
15+ }
16+
17+ {
18+ const json = {
19+ "" : {
20+ language : "fr" ,
21+ "plural-forms" : "nplurals=2; plural=n>1;" ,
22+ } ,
23+ Welcome : "Bienvenue" ,
24+ "There is %1 apple" : [
25+ "Il y a %1 pomme" ,
26+ "Il y a %1 pommes" ,
27+ ] ,
28+ } satisfies Gettext . JsonData ;
29+
30+ // $ExpectType Gettext
31+ instance
32+ . loadJSON ( json )
33+ . loadJSON ( json , "messages" ) ;
34+ }
35+
36+ {
37+ // $ExpectType Gettext
38+ instance . setLocale ( "fr" ) ;
39+ }
40+
41+ {
42+ // $ExpectType string
43+ instance . getLocale ( ) ;
44+ }
45+
46+ {
47+ // $ExpectType Gettext | string
48+ instance . textdomain ( ) ;
49+ // $ExpectType Gettext | string
50+ instance . textdomain ( "domain" ) ;
51+ }
52+
53+ {
54+ // $ExpectType string
55+ instance . gettext ( "message id" ) ;
56+ // $ExpectType string
57+ instance . gettext ( "message id" , "arg 1" , "arg 2" ) ;
58+ }
59+
60+ {
61+ // $ExpectType string
62+ instance . ngettext ( "There is %1 apple" , "There are %1 apples" , 0 ) ;
63+ // $ExpectType string
64+ instance . ngettext ( "There is %1 apple" , "There are %1 apples" , 0 , "arg 1" , "arg 2" ) ;
65+ }
66+
67+ {
68+ // $ExpectType string
69+ instance . pgettext ( "There is %1 apple" , "There are %1 apples" ) ;
70+ // $ExpectType string
71+ instance . pgettext ( "There is %1 apple" , "There are %1 apples" , "arg 1" , "arg 2" ) ;
72+ }
73+
74+ declare const nullableStr : string | null | undefined ;
75+ declare const nullableNum : number | null | undefined ;
76+ {
77+ // $ExpectType string
78+ instance . dcnpgettext ( nullableStr , nullableStr , "There are %1 apples" , nullableStr , nullableNum ) ;
79+ // $ExpectType string
80+ instance . dcnpgettext ( nullableStr , nullableStr , "There are %1 apples" , nullableStr , nullableNum , "arg 1" , "arg 2" ) ;
81+ }
82+
83+ {
84+ // $ExpectType string
85+ instance . strfmt ( "There is %1 apple" ) ;
86+ // $ExpectType string
87+ instance . strfmt ( "There is %1 apple" , "arg 1" , "arg 2" ) ;
88+ }
89+
90+ {
91+ // $ExpectType string[]
92+ instance . expand_locale ( "fr" ) ;
2493}
0 commit comments