Multi-language text and viewer content
Image localisation
When using a multi-language website to reach a wider audience, you can display images which are specific to each language site.
EN
ES
FR
For this solution the filename schema is the same (-en.jpg, -es.jpg, -fr.jpg etc.) and the website URL must contain the language, eg:
-
https://en.yourwebsite.com
-
https://es.yourwebsite.com
-
https://fr.yourwebsite.com
The code looks like this:
<img class="Sirv" data-src="https://demo.sirv.com/demo/localization-by-country-and-language/pringles-local-file_us-EN.jpg" />
Write a script to incorporate all your languages. The example script below uses English en, Spanish es and French fr but you can use as many languages as you want, simply update the SMV_SUPPORTED_LANGUAGES section:
<script type="text/javascript">
// Define supported languages
var SMV_SUPPORTED_LANGUAGES = ['en', 'es', 'fr'];
// Define default language
var SMV_DEFAULT_LANGUAGE = 'en';
// Get current language from the URL
function smvGetPageLanguage() {
var reCurLang = new RegExp('\\/(' + SMV_SUPPORTED_LANGUAGES.join('|') + ')\\/', 'i');
var matches = document.location.pathname.match(reCurLang);
if (matches) {
return matches[1];
}
return SMV_DEFAULT_LANGUAGE;
}
</script>