Closed dianeryanto closed 4 years ago
Hi there!
I've just made a large update to do what you need. Please see the readme file on "template strings": https://github.com/Irrelon/jquery-lang-js#dynamic-data--template-strings
This new version is the first large update for a long time and I don't think I broke anything but let me know if you have any issues.
P.S. you will need to update to version 4.0.0 in order to use this new feature.
Closing as this has now been resolved ;)
Awww, i dont think you'll response me but you just made new update for my needs.
Really big thanks Sir! š
Hi Sir, your update is working perfectly. But i think i have new issue.
Based on your example, we must define like this for dynamic alert content.
"token": { "myTranslationToken":"Hello ${data.firstName} ${data.lastName}" }
alert(window.lang.translate("myTranslationToken", "en", {"firstName: "Amelia", "lastName": "Earhart"}));
Result :
Hello Amelia Earhart
The problem is how to create dynamic default language alert content too?
Can i create myTranslationToken
for dynamic default language too?
My Expected Result like this
Default Language:
Halo Amelia Earhart
and after translate becomeHello Amelia Earhart
In html tag we define like this
<div lang="id">Default Language</div>
"token": { "Default language":"Translate from Default Language" }
When we change language, the result become<div lang="en">Translate from Default Language</div>
Any idea sir @Irrelon ? Thanks before Sir, i hope im not bother you
Hey ya! No problem to ask questions! If I have time I will always try to help.
You can create a language json file for your default language and load it the same way you load the other languages.
If your default language is āidā and your second language is āenā then you would create two json files, one called āid.jsonā and one called āen.jsonā and then both will have the token āmyTranslationTokenā with their respective value āhalo ...ā and āhello...ā
Does that make sense? Iām replying from my phone at the moment so I canāt insert code examples but the readme.md was updated and includes an example :)
Please let me know if that helps you :)
Already try your suggest to create 2 different json id.json
and en.json
and both of them have token myTranslationToken
with different language.
Load the json
var lang = new Lang(); lang.dynamic('en', '/plugin/jquery-lang-js-master/js/langpack/en.json'); lang.dynamic('id', '/plugin/jquery-lang-js-master/js/langpack/id.json'); lang.init({ defaultLang: 'id'})`
But when i try to change language to en -> id
or id -> en
,
The output still in one language, not dynamically change.
my alert like this
alert(window.lang.translate("myTranslationToken", "id", [value1, value2]));
Am i wrong or miss something?
Sir, i think i got trick for solve my problem but i think not best solution.
i create actual_lang
variable who dynamically change based on what languages we choose and put it on on second parameter.
Like this and working perfectly.
alert(window.lang.translate("myTranslationToken", actual_lang, [value1, value2]));
So i think i can close my problem. Thanks for your help sir.
Hey! I'm at my computer now.
I fully understand what your problem is now! :)
So for the translate()
method you needed to be able to "fill in" the current selected language.
This is very simple. Just pass undefined as the second parameter :)
e.g.
alert(window.lang.translate("myTranslationToken", undefined, [value1, value2]));
When you don't specify the language to use, the translate()
method will default to the current language.
Yes, already try using undefined
or get the actual language from cookies and both of them working perfectly.
But i prefer using undefined
based on your suggest as project owner š
Thanks for your help sir !
Hi Sir, thanks for your great work it's really help.
But i found some problem, i don't know how to translate dynamic alert content. Already read your documentation, you suggest using
window.lang.translate
for alert, but it for static content.Example for dynamic alert content
alert("Are you sure to delete "+name+" product");
Any idea for solve this problem?
Thanks before Sir.