We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3349
    • 126 Posts
    Hi

    I have a structured template in my modx site for walking holidays. Nn the right hand side of each walking holiday page there are fixed headings:

    More Details
    Location
    Gallery

    My question...

    These headings need to be translated using YAMS when user switches languages but do I need to create TV’s for each of them (which I would see as pointless as they are fixed hedaings never to be updated/changed) OR is there some code I can put into the template to do the translation depending on what language is set.

    Hope someone can help

    bS
    • You could try adding them to the main YAMS language files and using a YAMS snippet call in your template to activate the placeholders.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 3349
        • 126 Posts
        Thanks for replying Susan

        Can you tell me which file it is you are referring to? I’ve had a look in the modules/yams/lang folder but cant see anything obvious for where/how I should add the heading I want

        Thanks
        • The YAMS language files are used primarily for the module itself, and as far as I see in my own installations comes with English and French language files. But the YAMS snippet loads and initializes the $yams object, so the placeholders should be available from a snippet as well.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 36404
            • 307 Posts
            Hi,

            don’t know if you’ve solved your problem so, just in case, you’ve an easy way to do that in the templates
            [[YAMS? &get=`text` &from=`en::More details||fr::Plus de détails`]]

            done! smiley

            the only problem with this method is that it won’t allow you to use html tags or quotes without breaking.
            To solve this, i’ve imagined a little system based on a snippet and language files, once more, in case it helps...
            (edited ’cause i’ve found a lighter way to do this)
            i’ve a directory named langs in the assets/snippets/directory (you can put this anywhere you want, just call it with the right path in the coming snippet) in which i’ve two files
            lang_fr.php
            lang_en.php

            these files are set like this, for example lang_fr.php
            <?php
            $zilang = Array(); //$zilang not to conflict with a potential $lang array elsewhere
            $zilang['toto'] = "il est content toto"; //"toto is happy" in lang_en :)
            //and so on


            now, let’s have a look at our snippet called "langfile"
            <?php
            $yams   = YAMS::GetInstance();
            $langId = $yams->GetCurrentLangId();
            
            require( MODX_BASE_PATH . 'assets/snippets/langs/lang_'.$langId.'.php' );
            return $zilang[$text];
            ?>
            

            short and simple isn’t it ?

            and where you need one of those words/phrases
            [!langfile? &text=`toto`!]

            that’s all! you now have your own language files working smiley

            Hope it helps
            Have swing

              réfléchir avant d'agir
              • 3349
              • 126 Posts
              Thanks very much, the basic solution will do me for now but its good to know theres a solution for html tags too

              Nice one..

              bS