A simple .NET Script bundling translator, created to easily communicate with the ResourceManager
class and it's made in conjuction with the Microsoft.AspNet.Web.Optimization
bundler package in order to create translated scripts eliminating the need of creating global variables with translation keyvaluepairs.
These translated bundles are also cached by language, this means they won't be regenerated again, unless they change in the source code.
Simple check the Configuration Samples and add them to your project.
Then on the MVC's BundleConfig.cs
simple call the bundler as shown down below.
bundles.AddRange(ScriptTranslationBundle.Create("~/bundles/general", "~/Scripts/General/General.js"));
This will create bundles for all the avaiable cultures inside your CultureSettings configuration.
Use in between curly brackers the name of your resource file (.resx) and with a slash (/) name the key you want to use.
public success: string = "{JSTranslator/Success}";
public failed: string = "{JSTranslator/Failed}";
public loading: string = "{JSTranslator/Loading}";
Which will be rendered as the proper translation value.
EN:
var success = "Success";
var failed = "Failed";
var loading = "Loading";
PT:
var success = "Sucesso";
var failed = "Falhou";
var loading = "A Carregar";
Call the script on a razor page via
@ScriptBundleTranslator.Mvc.HtmlHelpers.LocalizedJsBundle("~/bundles/general")
- Microsoft.AspNet.Web.Optimization
- Microsoft.Web.Infrastructure (>= 1.0.0)
- WebGrease (>= 1.5.2)