coderifous / jquery-localize

a jQuery plugin that makes it easy to internationalize your web site.
465 stars 142 forks source link

Trigger localization based on URL? #80

Open vilav opened 8 years ago

vilav commented 8 years ago

Hi there

The plugin looks amazing. Is there a way to trigger a string's localization based on the URL of the page?

For instance, on website.com/fr, a string like "Hello" would be "Bonjour" Similarly on website.com/es, the string could be "Hola"?

Any tips on how to accomplish this?

alexwebgr commented 8 years ago

hi vilav

relying on the url for your persisting your language sounds kinda fragile to me depending how is your website setup i.e. how are you going to parse and populate the url implementations vary significantly but a high level flow would like this

have links that point to each language click the link read the parameter from url assign it to the plugin

would you be willing to consider a session based language switcher https://github.com/coderifous/jquery-localize/issues/77

perhaps you could extend it to read the params from the href attribute, where the full exists, instead of the data-lang attribute

regards alex

vilav commented 8 years ago

Do you have any example code how I can structure that? The URL will be setup in a way that the suffix of language (de/fr etc.) is always persistent in that piece of content. the URL could be a simpler trigger to toggle language content making it easy to integrate with static and cms-based sites, do you think so?

alexwebgr commented 8 years ago

the github editor ate my link ! click on number 77 in my previous post