LaxarJS / laxar-patterns

Utilities to implement standard event patterns in LaxarJS widgets
MIT License
5 stars 2 forks source link

i18n: string value should always directly be returned by localizer #6

Closed alex3683 closed 10 years ago

alex3683 commented 10 years ago

Currently the localizer checks if there is a valid language tag set in the model of the artifact and if there is none, without further tests the fallback value is returned. This behavior is not desired if the value to localize is a plain string. In this case the expectation is that the string is directly returned without any check for a language tag, as no localization is necessary / desired.

Possible fix: Change

function partial( i18nValue ) {
   var t = model.tags[ model.locale ];
   return t ? ax.i18n.localizer( t, fallback )( i18nValue ) : fallback;
}

to

function partial( i18nValue ) {
   if( typeof i18nValue === 'string' ) { return i18nValue; }
   var t = model.tags[ model.locale ];
   return t ? ax.i18n.localizer( t, fallback )( i18nValue ) : fallback;
}
x1B commented 10 years ago

Fixed on master (v0.11.0) and release-0.10.x (v0.10.2)