1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to specify a language for a XenForo_Phrase

Discussion in 'XenForo Development Discussions' started by AndyB, Nov 17, 2014.

  1. AndyB

    AndyB Well-Known Member

    I have an add-on called Weekly Digest:


    It runs from a XenForo Cron once a week. Everything is fine, except for those forums which run other languages besides English.

    What I would like to know is in the PHP which the Cron runs, I have several phrases, for example:

    // get subject
    $subject = new XenForo_Phrase('weeklydigest_subject');
    is there a way I can specify which language to select for this phrase? I know I could do a direct query on the database, but it would be nice if there was an easier way.

    Thank you.
  2. Chris D

    Chris D XenForo Developer Staff Member

    You don't need to specify a language for the phrase.

    As Mike already described, you need to pass the user's language into the Mail object.
  3. AndyB

    AndyB Well-Known Member

    Hi Chris,

    Thank you for looking at my question.

    Lets say for a moment that I'm not sending an email at all. Is there a way to specify specify which language a phrase would use? Of course outside a Cron this is automatic, but run from a Cron one needs to specify or else it defaults to the master phrase.
  4. Chris D

    Chris D XenForo Developer Staff Member

    The only possible thing you would ever need to do in a Cron is send an email or something similar. So it's a rather moot point, but you could in theory set it using the setLanguageId method of the phrase object before the phrase is rendered. Regardless, it still won't help you with your particular issue.
  5. AndyB

    AndyB Well-Known Member

    Thank you, Chris.

    This works perfect for my needs.

  6. Chris D

    Chris D XenForo Developer Staff Member

    In case anyone else stumbles across this thread, I will just quote the correct solution:

  7. xfrocks

    xfrocks Well-Known Member

    This may work if all users use the same language but will not work correctly if you need to change languages between users though FYI.

Share This Page