-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Adding language switcher #77
Comments
i guess you would have to persist somewhere like localStorage for example |
Hi Alex, I haven’t reply yet as I was trying to work this out by myself, but I have to admit my javascript skills are very basic and my attempt failed greatly.. I have tried something like this with anchors, but unfortunately doesn't work. I didn't even managed to get to localStorage part.. Could I ask for some more help please?! HTML <div id="languages" class="language-switcher">
<a href="#" id="en">ENG</a>
<a href="#" id="es">ESP</a>
</div> JS function onLanguageItemChange() {
if($("#languages a").attr("id") == "es") {
$("[data-localize]").localize("application", { language: "es" });
}
else if($("#languages a").attr("id") == "en") {
$("[data-localize]").localize("application", { language: "en" });
}
}
$(document).ready(function() {
$("#languages a").attr("id").change(onLanguageItemChange).change();
}); |
hi klara i was thinking something more like this https://jsfiddle.net/s88xvzan/ dont forget to include Session.js in your html file another benefit for using anchors is that you can add flag icons instead of text very easily let me know me how it goes |
hi Alex, it works like a charm!! many many thanks for the help! |
happy to help ! |
Hi, I'm getting a "XHR failed loading: GET "https://mysiteweb/test/lenguaje-es.json" error on chrome console, after of triying many times the switch language it works. Any ideas? |
there are many reasons a XHR might fail. Can you share more info for example the HTTP status code ?
a common reason for failing is also typos or wrong paths |
@alexwebgr hi, i test your code, why it's not working. when i click on it, it won't change.
if(lang === undefined) { $(".languageSwitcher a").on({
}); function doLocalize(lang) {
}` |
make sure that the paths to the language files are correct and check the console to see if you are getting any errors :) |
@alexwebgr hi, there is no error shows up in console. so that's why i'm asking what's wrong with the code. and the path is correct as well. |
your code looks ok to me but to be honest it has been ages since I last
used this plugin so I'm not sure how much help I can be :(
what I would suggest though, is to double check the documentation, build a
small PoC in jsfiddle for example and then start adopting it to your use
case
…On Sat, 8 Jun 2019, 02:16 wegee-us, ***@***.***> wrote:
@alexwebgr <https://github.com/alexwebgr> hi, there is no error shows up
in console. so that's why i'm asking what's wrong with the code. and the
path is correct as well.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#77?email_source=notifications&email_token=AA2JR35ENCSXJSV7QTEUD7LPZMCALA5CNFSM4CG3HJHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXHKEVY#issuecomment-500081239>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA2JR34WUV3JV4HNFXEESZLPZMCALANCNFSM4CG3HJHA>
.
|
@alexwebgr ok, thanks for your reply, i will try something else. |
Hi, this plugin is great! thanks for sharing it!
I have already set it up on one site, but would love to add a language switcher for users to have an option. I have found a nice solution in your issue: #17
The only problem is that when I change a page, it switches back to the previous language. Any ideas how to adjust it?!
HTML
JS
plus two files language-en.json and language-es.json
many thanks in advance!
The text was updated successfully, but these errors were encountered: