Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.2.0.0] Language locale is not saved #4050

Closed
gob33 opened this issue Mar 4, 2016 · 7 comments

Comments

Projects
None yet
5 participants
@gob33
Copy link
Contributor

commented Mar 4, 2016

When creating a new language, there is no more locale (in the form and DB).
So that it is no more possible to use PHP setlocale() for formatting dates, time, etc...in extensions.

langages
Ex:

setlocale(LC_TIME, explode(',', $language['locale']));

$language['code'] could be used instead but not sure it displays accents correctly (like with fr-FR.UTF-8).
Rather annoying.

@gob33

This comment has been minimized.

Copy link
Contributor Author

commented Mar 5, 2016

$language['code'] should be the ISO 639 language code with 2 or 3 letters, ex 'gb'.
$language['directory'] should be the new directory 'en-gb' (giving the langage file with the same name).
$language['image'] should be 'en-gb.png' (can be deduced from directory name).
This is complete non-sense. Keep your 'en-gb' directory but revert language form to OC2.1.0.2 with 'locale' and 'directory' and not just with the 'code' field.

@b-and-p

This comment has been minimized.

Copy link

commented Mar 9, 2016

I find this to be an issue as well, this will require updating and releasing another version of any 3rd party modules that use language in some way, just tested one of my modules on a fresh install of 2.2.0.0 and find it broken in both - admin and store front because of this.

Language in catalog has code set to 'en', in admin it is set to 'en-gb', this breaks my module setting array, as the language code is used as key.
Also, the key image is missing from language object in admin, so this breaks the flag icons.

Catalog language object

 object(Language)[37]
  private 'default' => string 'en-gb' (length=5)
  private 'directory' => string 'en-gb' (length=5)
  private 'data' => 
  array (size=76)
  'code' => string 'en' (length=2)
  'direction' => string 'ltr' (length=3)
  'date_format_short' => string 'd/m/Y' (length=5)
  'date_format_long' => string 'l dS F Y' (length=8)
  'time_format' => string 'h:i:s A' (length=7)
   ...

Admin language object

 array (size=5)
 'language_id' => string '1' (length=1)
 'name' => string 'English' (length=7)
 'code' => string 'en-gb' (length=5)
 'sort_order' => string '1' (length=1)
 'status' => string '1' (length=1)

Are these and other core changes documented anywhere?

@mhcwebdesign

This comment has been minimized.

Copy link

commented Mar 13, 2016

There are indeed some changes to the way languages are handled.

To start with: OpenCart 2.2.0.0 doesn't use the DB fields 'directory', 'image' and 'locale'. The name of the language folder always has to be same one as the language code, e.g. something like 'en-gb' or 'de-de'. The language folder also ought to have the image file, e.g. 'catalog/language/en-gb/en-gb.png' or 'catalog/language/de-de/de-de.png' etc.

It looks like the only reason why the database still has the 'image', 'locale' and 'directory' fields in there is for backward compatibility with previous Opencart versions and their language packs.

Having said that, I agree with the previous comments that the 'locale' field should be suppported again for the reasons mentioned by above posters, e.g. the need to use 'locale' in 3rd party extensions.

@gob33

This comment has been minimized.

Copy link
Contributor Author

commented Mar 14, 2016

Over 2.1.0.2, there was nothing to change here, just adopting the convention that image and directory new names will be typed like 'language-country' in the language form.

@gob33

This comment has been minimized.

Copy link
Contributor Author

commented Mar 19, 2016

I have tried a workaround, building a locale with the code:

if (!empty($language['locale'])) {
  $locale = $language['locale'];
} elseif (!empty($language['code'])) {
  $data = explode('-', $language['code']);
  $locale = $data[0].'_'.strtoupper($data[1]).'.UTF-8,'.$data[0].'_'.strtoupper($data[1]).','.$data[0].'-'.$data[1];
} else {
  $locale = null;
}
setlocale(LC_TIME, explode(',', $locale));

which gives "fr_FR.UTF-8,fr_FR,fr-fr".
But doesn't work on Windows which expects "french" (entered in previous OC versions) to get the installed locale "French_France.1252"
So that it is absolut necessary to revert back changes here as it was before 2.2.0.0.

@danielkerr

This comment has been minimized.

Copy link
Contributor

commented Jun 16, 2016

ok will add local but the folder names remain the same. its useful for the opencart installer and if the site has no DB connection to still be able to work without the DB.

danielkerr added a commit that referenced this issue Jun 16, 2016

@danielkerr danielkerr closed this Jun 16, 2016

@Ergotron-Mexico

This comment has been minimized.

Copy link

commented Apr 7, 2018

I have problems...!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.