turquoiseowl / i18n

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

i18n damages a vendor script in a bundle #301

Closed artkpv closed 7 years ago

artkpv commented 7 years ago

Thank you for the great tool!

I can't make i18n not to change a kendo script.

In web.config:

<add key="i18n.BlackList" value=".\Scripts\vendor;.\Content;..\external\;.\obj;.\bundles\vendor" />

In my cshtml:

@Scripts.Render("~/bundles/vendor/kendo",

In Global.asax.cs:

        // Blacklist certain URLs from being 'localized' via a callback.
        i18n.UrlLocalizer.IncomingUrlFilters += delegate (Uri url)
        {
            if (Regex.IsMatch(url.LocalPath, "(?i)bundles[\\/]vendor"))
                return false;

            return true;
        };
        i18n.UrlLocalizer.OutgoingUrlFilters += (url, requestUrl) =>
        {
            if (Regex.IsMatch(url, "(?i)bundles[\\/]vendor"))
                return false;

            if (Regex.IsMatch(requestUrl.LocalPath, "(?i)bundles[\\/]vendor"))
                return false;
            return true;
        };

`

It breaks with "Uncaught SyntaxError: Unexpected token ]" where triple ']]]' where replaced.

How can I make it to ignore it?

turquoiseowl commented 7 years ago

There's another setting i18n.LocalizedApplication.Current.UrlsToExcludeFromProcessing that may help. The UrlLocalizer.XXXX filters control localization of the URL strings themselves, not the content.

Having said that, are you sure the problem isn't because you have a JS array with three closing braces ]]]? It's a recognized problem with the default nugget markup (and why many use [#[message]#] style markup). See readme for more details.

artkpv commented 7 years ago

@turquoiseowl Thanks for the answer! It works with UrlsToExcludeFromProcessing.

The error is for sure because of a JS array. Here it is: =t.center().x;returni-5,t.y1],[i+5,t.y1],[i replaced.