Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You can use the “locale” filter to set it to any value you want, though you need the appropriate language files installed for translations to work as expected. Hook with a large priority argument so your callback has the final say in the locale used. Check the boolean value of REST_REQUEST to ensure you’re dealing with an API request.
    https://developer.www.ads-software.com/reference/hooks/locale/

    Thread Starter kghugo2000

    (@kghugo2000)

    Hi,

    Thank you for your reply. I have changed the locale through the filter, and get_locale() returns the locale I want right now. However, translations did not change accordingly right now. (I guess the .mo files are not called, as they have already loaded when the theme loaded.). How can I check that, or call .mo file deliberately(Maybe make a condition make .mo file load again when REST API request fired)?

    Thank you so much for your help.

    • This reply was modified 4 years, 9 months ago by kghugo2000.
    Thread Starter kghugo2000

    (@kghugo2000)

    Problem solved! I just need to use load_theme_textdomain(); after changing locale to get the translation.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Locale changed during Ajax call with REST API’ is closed to new replies.