Localización Json not updating frontend content

Hi, I’m using Translate plugin and trying to load translation via json files on theme/lang folder (en.json - es.json). ActiveLocal changes correctly but only shows content in English. This is the code I’m using to switch between locales:

<?php

function onStart()
{
    // Get the active locale from the session
    $activeLocale = \Session::get('activeLocale');

    // Set the active locale if it exists, otherwise use the default locale
    $this['activeLocale'] = $activeLocale ?: \RainLab\Translate\Classes\Translator::instance()->getDefaultLocale();
}

function onSwitchLocale()
{
    $locale = input('locale');
    if ($locale && in_array($locale, ['en', 'es'])) {
        \RainLab\Translate\Classes\Translator::instance()->setLocale($locale);
        \Session::put('activeLocale', $locale);
    }

    return response()->json(['success' => true]);
}

Additionally, I calle the translation value as {{ 'welcome_message' | trans }} which seem to be correct. Also, if I do something like this, it works: {{ activeLocale == 'es' ? 'Hola' : 'Hello' }}

What may I am doing wrong?

Hey @Guzz

did you find a solution? I’d need to do the same actually

The translate plugin uses |_ to translate messages (GitHub - rainlab/translate-plugin: Enables multi-lingual sites) and themes can provide default values for those codes (GitHub - rainlab/translate-plugin: Enables multi-lingual sites) but those methods are imho not interchangeable.

I’m actually not sure if the Translate plugin takes JSON based theme localisation into consideration when translating, I think those are 2 separate methods.

1 Like

Yes you are right, those are 2 separate methods