totaljs / framework4

Total.js framework v4
https://www.totaljs.com
Other
99 stars 36 forks source link

localize script files #18

Closed dispbd closed 3 years ago

dispbd commented 3 years ago

Hello. Is it possible to localize script files? Some of the content for the user is drawn by javascript. It is important to use the built-in localization mechanism, as it is extremely simple and convenient. DEF.onCompileScript cannot be rewritten, since it is only suitable for code inside the view. I could put the code inside the script tag, but that causes a number of other difficulties.

The method can be modified. For example: @{js (url, [localize])}; This, of course, will affect the cache, since different languages ​​need different files. But I think the problem can be easily solved by binding the prefix to the file path, to the example _ru, _en, etc. Or is there some other way?

petersirka commented 3 years ago

Hi @dispbd. This isn't possible because all static files are cached by the browser (with except html files). I recommend to localize text in the HTML files/views and transform them to the JavaScript.


If you want to localize static files anyway then you need to create a custom file handler, but there won't work e.g. merging.

dispbd commented 3 years ago

Thanks. Let's create my own handler.