Translate Country and Region Easy store - Forum | JoomShaper
Solved EasyStore

Translate Country and Region Easy store

Asked by Tilka 1 year ago Last activity 1 year ago

Accepted answer

Marked as the solution
Tilka Asked this

You misunderstood what I was talking about, I meant a dictionary of all countries and regions. There is no word in the file you specified, there is only a header for the Selector field. I already found it in the media/data folder.

5 more replies

Mehtaz Afsana Borsha Staff

Hello,

Thanks for contacting us.

You will find this in this file:

language/en-GB/com_easystore.ini

Please follow the documentation:

EasyStore Translation

Best regards

Mehtaz Afsana Borsha Staff

Sorry for misunderstanding and glad to know that you have already fixed the issue.

Imservan

Hello Tilka, yes I would like that too.
I am also looking for the file where I can, for example, translate the word “Germany” into German and so on.
The same is with the federal states, for example the word “Bavaria” in Bavaria and so on.
Have you already found the solution? Best regards Imservan

Tilka Asked this

Hi,

it's here /media/com_easystore/data/countries.json

Imservan

Thank you Tilka, for the quick support

RA

Hello everybody - I am having the same issue, but simply changing the countries.json is not really a good solution, since the changes would be discarded when an easystore update is performed.

I would propose a different solution.

The logic for fetching the translation from countries.json are located here:

  • \JoomShaper\Component\EasyStore\Site\Controller\CheckoutController::getCountries
  • \JoomShaper\Component\EasyStore\Site\Controller\CheckoutController::getStates
  • \JoomShaper\Component\EasyStore\Site\Helper\EasyStoreHelper::getCountryStateFromJson

seem to be responsible for providing the counties and state strings. It would make sense to make a translation key lookup here, so that we could use the standard Joomla language/translation management system.

e.g. \JoomShaper\Component\EasyStore\Site\Controller\CheckoutController::getCountries could be changed this way.


use Joomla\CMS\Language\Text;
// ...
public function getCountries()
    {
        $countriesData = $this->loadCountriesData();

        $settingsModel     = new SettingsModel();
        $countryWithStates = $settingsModel->getCountriesWithStates();

        $codes = array_keys($countryWithStates);

        $countries = ArrayHelper::findByArray(function ($haystack, $item) {
            return ArrayHelper::find(function ($value) use ($item) {
                return $value->numeric_code == $item;
            }, $haystack);
        }, $countriesData, $codes);

        // original code
        // $countries = ArrayHelper::toOptions(function ($country) {
        //    return (object) [
        //        'label' => $country->name,
        //        'value' => $country->numeric_code,
        //    ];
        // }, $countries);

                // possibly new code 
        $countries = ArrayHelper::toOptions(function ($country) {
                    $languageString = 'COM_EASYSTORE_COUNTRY_' . $alpha_3;
                        $translation = Text::_($languageString);

                        // use translation if translation was found (e.g. when translation is not the same as languageString)
            return (object) [
                'label' => $translation == $languageString ?  $country->name : $translation,
                'value' => $country->numeric_code,
            ];
        }, $countries);

        $this->sendResponse($countries);
    }

This would be backwards compatible (since the fallback mechanism would use the country name from the JSON file) and it would be possible to override the String for exemple like this:

Germany:

COM_EASYSTORE_COUNTRY_DEU=Deutschland (for de translations)
COM_EASYSTORE_COUNTRY_DEU=Germany (for en translations)
...

Mehtaz Afsana Borsha Staff

Hi RA,

Thanks for sharing the solution. I hope other users are also get help from it.

-Regards.

RA
1 year ago · edited

Hi Mehtaz,

thanks for the quick response, this is actually more like a feature request (the normal user wont see that as any kind of help). With this approach you will be able to set the language string in the CMS and it would not break when an EasyStore Update occurrs.

It would make sense to forward this to the development team, so they can consider including this (or some variation of this) feature.

Normally I would post this kind of proposal on GitHub, but EasyStore is closed source (or at least not on GitHub or Private).

Thanks again

Mehtaz Afsana Borsha Staff

Thanks for your suggestions. I will inform our DEV team about it.

Log in to reply.