Comments (2)
I put together a code sample demonstrating how to achieve this using my library.
I don't know where the JSTranslator type comes from (I assume it's some custom component) so I implemented a simple translator transformation. To plug in your own implementation, all you need to do is implement the IBundleItemTransform interface (or inherit from BundleItemTransform class) and register your bundles using this transformation as shown here.
Furthermore, I use PO-based translation in the sample. It can be replaced to a resource based or other localization mechanism easily. Just read my comments in the Startup class.
from bundling.
Thanks Adams for guiding.
I have implemented Translator my way.
It changes current culture via a dropdown available on site footer, just as you described in your sample app. Localized JS bundle is loaded via
<script src="~/bundles/js/modules/myModulesBundle.@(currentCulture.Name).js"></script>
Bundling is done in Startup.cs =>Configure() method like so:
app.UseBundling(bundles =>
{
// building an advanced configuration in code
//bundles.AddCss("/virtual-path/to/bundle.css")
// .Include("/physical-path/to/include.css")
//.Include("/another/physical-path/to/pattern*.css")
//.Exclude("/**/*.min.css");
//bundles.AddLess("/virtual-path/to/less-bundle.css")
// .Include("/physical-path/to/main.less");
foreach (var culture in SupportedCultures)
{
bundles.AddJs($"/js/modules/myModulesBundle.{culture.Name}.js")
.Include("/js/module1.js")
.Include("/js/module2.js")
// this is THE KEY STEP: insert the translator in the bundle item transformation pipeline
.UseItemTransforms(transforms => transforms.Insert(0, new JSTranslator()));
}
});
And here is my JSTranslator component
public class JSTranslator : BundleItemTransform
{
public override void Transform(IBundleItemTransformContext context)
{
string translated = TH.STranslator(context.Content); // TH is some Helper class to do the exact translation
context.Content = translated;
}
}
from bundling.
Related Issues (16)
- Cannot access node_modules folder HOT 1
- Vuejs HOT 5
- .Net Core 3 issues HOT 2
- Does it work with .NET Framework 4.7? HOT 5
- Using CDN HOT 1
- Question: How to handle client side caching HOT 4
- Tree shaking in EcmaScript HOT 2
- EcmaScript - NullReferenceException when variable is not declared HOT 1
- Render individual includes HOT 8
- Add option for generating source maps
- Issue when script file has been modified outside of Visual studio HOT 5
- Negative number invalid for list HOT 1
- JS: Multiple mobile versions give syntax errors after bundeling. HOT 5
- asp-append-version tag doesn't seem to work with bundled script HOT 3
- Are there plans to update bundling tools to target .NET 7? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bundling.