EasyLingual, plugin to create multilingual sites v0.99
Description:
EasyLingual gets a ISO(2char) language code via "&lang" GET query and save it as a MODx cookie ({&dollarfix;} _SESSION).
This plugin replaces
[%lang%] with 2char language like en, fr, fa, ... (will be EMPTY if current language is default language)
[%language%] with lowercased language like english, french, persian, ... (will be EMPTY if current language is default language)
[%LANG%] with 2char language like en, fr, fa, ... (always)
[%LANGUAGE%] with lowercased language like english, french, persian, ... (always)
[%dir%] with "rtl" when language is RTL else "ltr"
[%align%] with "right" when language is RTL else "left"
in Templates, document Content and document Introtext
before parsing MODx tags, so you can use it in chunk names, snippets names and parameters and specially template variables.
EasyLingual gets language via "lang" GET query so you should add links like below for choosing language:
<a href="[~[*id*]~]
&lang=en" title="English">English</a>
<a href="[~[*id*]~]
&lang=fa" title="Persian">Persian</a>
Examples of usage:
To create a multilingual site, you need to create MODx document fields which you need as TVs, for example in my site only "page title" and "content" need to change for each language, so i create a textarea TV (with editor) and name it "
decontent" and another for page title "
depagetitle". So i need to put TV below in my template instead [*content*]:
when user chooses the "German", this TV will change to [*
decontent*] and in standard mode, [%lang%] is empty and TV will be [*content*].
EasyLingual
ONLY converts tags in Templates, Page content and page Introtext. it means if i use way above, i can use [%%] tags in value of [*content*] but i can’t use it in value of [*
decontent*] TV! but maybe in need to use plugin tags as page content.
In this way i should create another TV like [*
encontent*], put [*content*] in my template, and put tags below in PAGE CONTENT:
So when language is English, [*content*] contains [*
encontent*] and when language is German [*content*] contains [*
decontent*] and put other snippets and chunks and tags current document.
This plugin DOES NOT converts [% %] in chunks but if you need use different chunks as tpls, You must create a chunk for each language like this {{
[%LANGUAGE%]Chunk}}, so if language is Persian it will be {{
persianChunk}} in snippets like Ditto:
[[Ditto? &language=`[%LANGUAGE%]` &tpl=`[%LANG%]_ditto`......]]
so when language is Espanish, snippets will be
[[Ditto? &language=`espanish` &tpl=`es_ditto`......]]
You can use it in chunk tags: {{
[%language%]Chunk}}, so if language is French, it will be {{
frenchChunk}}
EasyLingual tags also converts in placeholder tags for your custom snippets.
EasyLingual also has feature for RTL languages. For this languages, using translations is not enaugh and usually the views must change to LTR and RTL too. So you can use [%dir%] and [%align%] tags in your templates (e.g.
<div dir="[%dir%]" align="[%align%]">)
It let you create dynamic templates for RTL and LTR languages
Installation:
1. Create a plugin, copy/paste this contents to plugin codes, name it "EasyLingual" and put "plugin to create multilingual sites v0.99" in description.
2. In Configuration tab, copy.paste code below in "plugin configuration" fields
&default_lang=default language;string;
press button and type 2-char language as default language else plugin will use MODx manager_lang_attribute.
3. In Events tab, check events below:
OnLoadWebDocument
4. Save it. Create necessary TVs, Chunks and Snippets. Put plugin valid tags in Templates, Document content and Document introtext.
REMEMBER
EasyLingual ONLY converts [% %] tags in Templates, Page content and page Introtext.
NOT in TVs and CHUNKs!
MODx caches only one language data of page. so multilingual pages MUST be
uncachable!
EasyLingual runs on Load Web Document, it must be in top of execution order of other plugins.!
Good luck