On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Hello,

    I couldn’t find a solution for my problem.
    I want to manage about five to six different languages with YAMS. The installation was no problem. But now I want to have something like a fallback solution:
    If there’s no content in the chosen language the content of the default language should appear.

    How can I do that?

    • Hi Michael.

      Sorry for the delay in replying. There is nothing built into YAMS at present that will allow automatic falling back to the default language.

      You can get close to what you want using some tricks, but there is currently no way that is both elegant and simple I’m afraid.

      Here are some ideas...

      A) The multilingual template variables created by YAMS (like pagetitle_en) can be edited manually and given default values. So you could set a default value for the non-default language fields to some text that says "not yet translated" (in the appropriate language.)

      B) Another approach is to use a [tt]((yams_data:docId:fieldname))[/tt] placeholder to pull in data from the default language template variable into a non-default language template variable. For example, for document number 3, if the default language was English with id [tt]en[/tt], then you could make the English page title appear in a different language pagetitle field by inserting [tt]((yams_data:3:pagetitle_en))[/tt] in that field.

      Clearly, the text that needs to be entered is different for each document and each field... so this approach is not very practical since setting up the default values would mean editing each field of each document.

      C) What we want is a way to assign the docId automatically so that the ((yams_data)) placeholder can be used as the default value of the non-default language multilingual template variables. One simple way of doing this would appear to be to use [tt]((yams_data:[*id*]:pagetitle_en))[/tt] as a default value for the non-English multilingual pagetitle TVs. However, the problem with this approach is that when evaluated in the context of a ditto call, this will always evaluate to the English page title of the document containing the Ditto call rather than the source document. In the context of a Ditto call you’d need [tt]((yams_data:[+id+]:pagetitle_en))[/tt] instead. I haven’t yet found a way around this.

      Hope that helps.
        YAMS: Yet Another Multilingual Solution for MODx
        YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
        Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
      • Hi,
        I know this comes a bit late, but I was trying to solve the same problem in my multilanguage templates, and I ended up using a YAMS construct like the one Paul suggested, in combination with PHx.

        For example, this code outputs the title in current language only if not empty. In case it is empty, it outputs the title in English:

        [+phx:if=`[[YAMS? &get=`data` &from=`pagetitle` &docid=`[*id*]`]]`:isnot=``:then=`[[YAMS? &get=`data` &from=`pagetitle` &docid=`[*id*]`]]`:else=`((yams_data:[*id*]:pagetitle_en))`+]

        I hope this can be useful, also please let me know if you found out better ways of doing that!