Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

query-wow/ScriptBundleTranslator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

39 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ScriptBundleTranslator

CodeFactor NuGet Badge GPL Licence HitCount

forthebadge forthebadge forthebadge

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.

How to add this to my project

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.

How to use

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")

Dependencies

  • Microsoft.AspNet.Web.Optimization
  • Microsoft.Web.Infrastructure (>= 1.0.0)
  • WebGrease (>= 1.5.2)