@@ -18,7 +18,9 @@ const gt = getGettextBuilder()
1818gt.gettext('some string to translate')
1919```
2020 */
21+
2122import type { AppTranslations } from './registry.ts'
23+
2224import { getLanguage , getPlural , translate , translatePlural } from './index.ts'
2325
2426export interface GettextTranslation {
@@ -34,14 +36,40 @@ export interface GettextTranslationContext {
3436export interface GettextTranslationBundle {
3537 headers : {
3638 [ headerName : string ] : string
37- } ,
39+ }
3840 translations : {
3941 [ context : string ] : GettextTranslationContext
4042 }
4143}
4244
43- class GettextBuilder {
45+ class GettextWrapper {
46+ constructor ( private bundle : AppTranslations ) {
47+ }
48+
49+ /**
50+ * Get translated string (singular form), optionally with placeholders
51+ *
52+ * @param original original string to translate
53+ * @param placeholders map of placeholder key to value
54+ */
55+ gettext ( original : string , placeholders : Record < string , string | number > = { } ) : string {
56+ return translate ( '' , original , placeholders , undefined , { bundle : this . bundle } )
57+ }
4458
59+ /**
60+ * Get translated string with plural forms
61+ *
62+ * @param singular Singular text form
63+ * @param plural Plural text form to be used if `count` requires it
64+ * @param count The number to insert into the text
65+ * @param placeholders optional map of placeholder key to value
66+ */
67+ ngettext ( singular : string , plural : string , count : number , placeholders : Record < string , string | number > = { } ) : string {
68+ return translatePlural ( '' , singular , plural , count , placeholders , { bundle : this . bundle } )
69+ }
70+ }
71+
72+ class GettextBuilder {
4573 private debug = false
4674 private language = 'en'
4775 private translations = { } as Record < string , GettextTranslationBundle >
@@ -81,6 +109,7 @@ class GettextBuilder {
81109
82110 build ( ) : GettextWrapper {
83111 if ( this . debug ) {
112+ // eslint-disable-next-line no-console
84113 console . debug ( `Creating gettext instance for language ${ this . language } ` )
85114 }
86115
@@ -99,38 +128,6 @@ class GettextBuilder {
99128
100129 return new GettextWrapper ( bundle )
101130 }
102-
103- }
104-
105- class GettextWrapper {
106-
107- constructor (
108- private bundle : AppTranslations ,
109- ) {
110- }
111-
112- /**
113- * Get translated string (singular form), optionally with placeholders
114- *
115- * @param original original string to translate
116- * @param placeholders map of placeholder key to value
117- */
118- gettext ( original : string , placeholders : Record < string , string | number > = { } ) : string {
119- return translate ( '' , original , placeholders , undefined , { bundle : this . bundle } )
120- }
121-
122- /**
123- * Get translated string with plural forms
124- *
125- * @param singular Singular text form
126- * @param plural Plural text form to be used if `count` requires it
127- * @param count The number to insert into the text
128- * @param placeholders optional map of placeholder key to value
129- */
130- ngettext ( singular : string , plural : string , count : number , placeholders : Record < string , string | number > = { } ) : string {
131- return translatePlural ( '' , singular , plural , count , placeholders , { bundle : this . bundle } )
132- }
133-
134131}
135132
136133/**
0 commit comments