@@ -138,7 +138,7 @@ const defaultStreami18nOptions = {
138138 language : 'en' ,
139139 disableDateTimeTranslations : false ,
140140 debug : false ,
141- logger : ( ) => { } ,
141+ logger : ( msg ) => console . warn ( msg ) ,
142142 momentLocaleConfigForLanguage : null ,
143143} ;
144144export class Streami18n {
@@ -205,7 +205,7 @@ export class Streami18n {
205205 debug : finalOptions . debug ,
206206 lng : this . currentLanguage ,
207207 parseMissingKeyHandler : ( key ) => {
208- this . logger ( `Missing translation for key: ${ key } ` ) ;
208+ this . logger ( `Streami18n: Missing translation for key: ${ key } ` ) ;
209209
210210 return key ;
211211 } ,
@@ -217,9 +217,14 @@ export class Streami18n {
217217 finalOptions . momentLocaleConfigForLanguage ;
218218
219219 if ( momentLocaleConfigForLanguage ) {
220- this . addOrUpdateMomentLocaleConfig (
221- this . currentLanguage ,
222- momentLocaleConfigForLanguage ,
220+ this . addOrUpdateMomentLocaleConfig ( this . currentLanguage , {
221+ ...momentLocaleConfigForLanguage ,
222+ } ) ;
223+ } else if ( ! this . momentLocaleExists ( this . currentLanguage ) ) {
224+ this . logger (
225+ `Streami18n: Streami18n(...) - Locale config for ${ this . currentLanguage } does not exist in momentjs.` +
226+ `Please import the locale file using "import 'moment/locale/${ this . currentLanguage } ';" in your app or ` +
227+ `register the locale config with Streami18n using registerTranslation(language, translation, customMomentLocale)` ,
223228 ) ;
224229 }
225230
@@ -228,14 +233,6 @@ export class Streami18n {
228233 return Moment ( timestamp ) . locale ( defaultLng ) ;
229234 }
230235
231- if ( ! this . momentLocaleExists ( this . currentLanguage ) ) {
232- console . warn (
233- `Locale config for ${ this . currentLanguage } does not exist in momentjs.` +
234- `Please import the locale file using "import 'moment/locale/${ this . currentLanguage } ';" in your app or ` +
235- `register the locale config with Streami18n using registerTranslation(language, translation, customMomentLocale)` ,
236- ) ;
237- }
238-
239236 return Moment ( timestamp ) . locale ( this . currentLanguage ) ;
240237 } ;
241238 }
@@ -270,8 +267,8 @@ export class Streami18n {
270267 validateCurrentLanguage = ( ) => {
271268 const availableLanguages = Object . keys ( this . translations ) ;
272269 if ( availableLanguages . indexOf ( this . currentLanguage ) === - 1 ) {
273- console . warn (
274- `'${ this . currentLanguage } ' language is not registered.` +
270+ this . logger (
271+ `Streami18n: '${ this . currentLanguage } ' language is not registered.` +
275272 ` Please make sure to call streami18n.registerTranslation('${ this . currentLanguage } ', {...}) or ` +
276273 `use one the built-in supported languages - ${ this . getAvailableLanguages ( ) } ` ,
277274 ) ;
@@ -311,6 +308,13 @@ export class Streami18n {
311308 * @param {* } customMomentLocale
312309 */
313310 registerTranslation ( language , translation , customMomentLocale ) {
311+ if ( ! translation ) {
312+ this . logger (
313+ `Streami18n: registerTranslation(language, translation, customMomentLocale) called without translation` ,
314+ ) ;
315+ return ;
316+ }
317+
314318 if ( ! this . translations [ language ] ) {
315319 this . translations [ language ] = { [ defaultNS ] : translation } ;
316320 } else {
@@ -319,6 +323,13 @@ export class Streami18n {
319323
320324 if ( customMomentLocale ) {
321325 this . momentLocales [ language ] = { ...customMomentLocale } ;
326+ } else if ( ! this . momentLocaleExists ( language ) ) {
327+ this . logger (
328+ `Streami18n: registerTranslation(language, translation, customMomentLocale) - ` +
329+ `Locale config for ${ language } does not exist in momentjs.` +
330+ `Please import the locale file using "import 'moment/locale/${ language } ';" in your app or ` +
331+ `register the locale config with Streami18n using registerTranslation(language, translation, customMomentLocale)` ,
332+ ) ;
322333 }
323334
324335 if ( this . initialized ) {
0 commit comments