turquoiseowl / i18n

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

Translate some Javascript files, but not others #367

Closed HenricRosvall closed 6 years ago

HenricRosvall commented 6 years ago

I have a problem with some minified Javascript-libraries that are destroyed by i18n because of arrays [[[ ]]], but at the same time other Javascript files need to be translated.

So I thought I'd just alter the Whitelist/Blacklists to only allow some of the Javascript files, but that had no effect what so ever.

So I found another issue here, where I learned that the translations seem to be done in two different stages, and it seemded that the late stage was the cuprit here. So I altered the i18n.LocalizedApplication.Current.ContentTypesToLocalize to not include Javascript files - and sure enough, the Javascript errors disappeared. But then it also stopped translating the Javascript files that actually need to be translated.

One option would of course be to change from [[[ ]]] to [&[ ]&], but I'd rather not, since we have multiple projects that inherits base classes that uses the [[[ notation. So that would require me to rebuild and update several different projects.

Is there some way around this that I might have missed? Perhaps some Whitelist/Blacklist system for the late binding, using the requested URL:s instead of file paths?

HenricRosvall commented 6 years ago

Seems I managed to solve it by modifying UrlsToExcludeFromProcessing, and adding the name of the problematic bundle to the RegEx i18n.LocalizedApplication.Current.UrlsToExcludeFromProcessing = new Regex(@"(?:\.(?:less|css)(?:\?|$))|(?i:i18nSkip|glimpse|trace|elmah|jquery_globalize)");