turquoiseowl / i18n

Smart internationalization for ASP.NET
Other
556 stars 156 forks source link

Quick fix for allowing unicode encoded strings to be translated #355 #356

Closed zingix closed 6 years ago

zingix commented 6 years ago

The following modification allows also JSON encoded responses to be translated correctly.

turquoiseowl commented 6 years ago

Looks good. How about a couple of optimizations?

Firstly, to avoid double lookup when not necessary:

if (text == null && msgkey.Contains("\\u")) { ... }

Secondly, how about creating the RegEx as a static member object of that TextLocalizer class, just in case it is re-created each time? Probably doesn't and in fact get's cached, but it would be in keeping with all other regex usage in the lib.

Cheers.

turquoiseowl commented 6 years ago

Suppose the Regex object could then also be used for test for a match, in preference to using Contains

zingix commented 6 years ago

Correct, that is a good point. Added a compiled regex and the required test.

turquoiseowl commented 6 years ago

Nice PR, thanks for contributing.