Hi,
I’ve used the tutorial ’Multilingual Websites with MODx (improved version)’ to make my website multilingual.
The translation of the content and Wayfinder navigation works great, but I have some static texts in my template. (static text in the header, titles in the sidebar,...) So small pieces of text that have to be translated too.
I was wondering how I can do this without making multiple templates for each language. Where do I put the text for all the languages (chunks, TV’s, docs,...)?
Thanks in advance!
Don't believe anything you read on the net. Except this.
-
☆ A M B ☆
- 24,524 Posts
I make these blocks chunks with a consistent naming convention such as title-en and title-de, and use a snippet to determine the language being used and output the appropriate chunk.
You could just have the text in the snippet itself and output the appropriate text string depending on the language.
Or you could use a plugin and do a search-and-replace of plugins in the documentContent before parsing, replacing a common chunk name with the language-specific one; or again have the plugin replace the chunk tags with the text itself.
Hi Susan,
Could you give me an example of the snippet determining the language and output the appropriate chunk, I’m a bit struggling with this
thanks!
Don't believe anything you read on the net. Except this.
maybe you can simply do this with tv’s?
[*sideboxTV*]
@INHERIT
then edit the folder lang and insert your chunk {{chunk-en}} or {{chunk-fr}}
CTRL+SHIFT+U - Clear Cache
CTRL+SHIFT+H - Hiding Heft Panel
CTRL+SHIFT+N - Fast Create Resource
CTRL+ALT+P - Preview Recource (in edit resorce window)
CTRL+ALT+S - Save
Hi Manu, If I use TV’s I probably have to change it on every document?
Now I got this snippet, which should call the different chunks:
<?php
if ($language = 'be') {
$output = "{{introtekst_be}}";
}
if ($language = 'gb') {
$output = "{{introtekst_gb}}";
}
if ($language = 'fr') {
$output = "{{introtekst_fr}}";
}
return $output;
?>
It works but it only calls the last chunk, introtekst_fr, for every language
Don’t understand why it doesn’t switch languages, I got this from
http://bobsguides.com/modx-snippets.html
Don't believe anything you read on the net. Except this.
Quote from: Hori76 at Aug 27, 2009, 03:35 AM
Hi Manu, If I use TV’s I probably have to change it on every document?
Actually if you use @inherit (as the default value in the tv) you need to change only one doc and all the sub-doc (with the inherit value) will get the value from the parent where the value is set. In your case you have 3 languages so you have to change 3 docs..
more info here :
http://svn.modxcms.com/docs/display/revolution/INHERIT+Binding
CTRL+SHIFT+U - Clear Cache
CTRL+SHIFT+H - Hiding Heft Panel
CTRL+SHIFT+N - Fast Create Resource
CTRL+ALT+P - Preview Recource (in edit resorce window)
CTRL+ALT+S - Save
Thanks Manu! Didn’t know I could do that! Works like a charm and it’s very easy! Modx keeps surprising me...
But I still want to know what’s wrong with the snippet, because probably I will need this in the future.
Don't believe anything you read on the net. Except this.
Looks like you need an extra = in the comparison spots.
A good explanation with examples:
http://www.w3schools.com/PHP/php_operators.asp
<?php
// initialize the $output
$output ='';
if ($language == 'be') {
$output .='{{introtekst_be}}';
}
if ($language == 'gb') {
$output .='{{introtekst_gb}}';
}
if ($language == 'fr') {
$output .='{{introtekst_fr}}';
}
if ($language != 'be' || $language != 'gb' || $language != 'fr') {
$output .='{{default_lang_chunk}}';
}
return $output;
?>
Hope this helps
Hi Breezer,
Sorry, but if I use the double == I don’t get any result.
For the rest this snippet outputs the same result as mine, just one chunk for all languages.
Don't believe anything you read on the net. Except this.
-
☆ A M B ☆
- 24,524 Posts
Hori76, a single equals sign is the assignment operator. It assigns the value on its right to the variable on its left. If you want comparison operators, you use == (and sometimes ===). So in your version using a single =, the last one will be the one you get, because the last thing you told it was to make $language contain ’fr’.
All the if does in this case is determine if the assignment was successful.
You aren’t getting any results because you cannot use MODx tags inside of PHP code. Use $modx->getChunk(’chunkname’) instead.