[MAGNOLIA-5125] Locale handling is broken with ISO 639-2 more than two letters Created: 18/Mar/13 Updated: 09/Feb/22 Resolved: 09/Feb/22 |
|
| Status: | Closed |
| Project: | Magnolia |
| Component/s: | None |
| Affects Version/s: | 4.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | Michał Kudła | Assignee: | Unassigned |
| Resolution: | Obsolete | Votes: | 0 |
| Labels: | ISO639-2, i18n, locale | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Gentoo Linux, Java 1.7.0 |
||
| Template: |
|
| Patch included: |
Yes
|
| Acceptance criteria: |
Empty
|
| Task DoD: |
[ ]*
Doc/release notes changes? Comment present?
[ ]*
Downstream builds green?
[ ]*
Solution information and context easily available?
[ ]*
Tests
[ ]*
FixVersion filled and not yet released
[ ] 
Architecture Decision Record (ADR)
|
| Bug DoR: |
[ ]*
Steps to reproduce, expected, and actual results filled
[ ]*
Affected version filled
|
| Date of First Response: |
| Description |
|
Apache Commons Lang support only two letter with wariants Apache org.apache.commons.lang.LocaleUtils if (len != 2 && len != 5 && len < 7) { throw new IllegalArgumentException("Invalid locale format: " + str); } Patch ugly, but showing what is broken
# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- HEAD
+++ Modified In Working Tree
@@ -109,8 +109,15 @@
@Override
public void i18nIze(Dialog dialog) {
+ final String configValue = dialog.getConfigValue("locale", null);
// TODO: should this be set in the aggregation state?
- Locale locale = LocaleUtils.toLocale(dialog.getConfigValue("locale", null));
+ Locale locale;
+ try {
+ locale = LocaleUtils.toLocale(configValue);
+ } catch (IllegalArgumentException iae) {
+ //language ISO 639 alpha-2 or alpha-3 language code,
+ locale = new Locale(configValue);
+ }
boolean isFallbackLanguage = i18nContentSupport.getFallbackLocale().equals(locale);
if (isEnabled() && i18nContentSupport.isEnabled() && locale != null) {
|
| Comments |
| Comment by Jozef Chocholacek [ 11/Nov/13 ] |
|
Only two-letter language codes can be used in Java6 (see the Javadoc of the Locale class constructors). This restriction has been relaxed in Java7, but Magnolia 4.4/4.5 still has to support Java6. |
| Comment by Magnolia International [ 21/Nov/13 ] |
|
The reason in our case though is not so much we have to support Java 6 than the fact that the length limitation is enforced by LocaleUtils; it seems never versions of commons-lang still enforce that, so the change isn't trivial. I thought we had our own LocaleUtils - but it could very well be that it's been removed years ago in favor of commons-lang. Agh. |
| Comment by Magnolia International [ 22/Nov/13 ] |
|
Michał, you're right; since java 7 this is indeed possible. Your fix however ignores country codes - and relying on this exception isn't something we want to do. Can't promise an ETA. However, I'd like to understand your use-case; are you using languages that don't have a 2-letter code, or somehow integrating with another system that uses the 3-letter codes, or..something else ? |