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)
...