< prev index next >

src/java.base/share/classes/sun/util/cldr/CLDRLocaleProviderAdapter.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 61,72 **** --- 61,78 ---- // Assumption: CLDR has only one non-Base module. private final LocaleDataMetaInfo nonBaseMetaInfo; // parent locales map private static volatile Map<Locale, Locale> parentLocalesMap; + // language aliases map + private static volatile Map<String,String> langAliasesMap; + // cache to hold locale to locale mapping for language aliases. + private static final Map<Locale, Locale> langAliasesCache; static { parentLocalesMap = new ConcurrentHashMap<>(); + langAliasesMap = new ConcurrentHashMap<>(); + langAliasesCache = new ConcurrentHashMap<>(); // Assuming these locales do NOT have irregular parent locales. parentLocalesMap.put(Locale.ROOT, Locale.ROOT); parentLocalesMap.put(Locale.ENGLISH, Locale.ENGLISH); parentLocalesMap.put(Locale.US, Locale.US); }
*** 139,148 **** --- 145,170 ---- locs[index++] = Locale.forLanguageTag(tag); } return locs; } + private Locale applyAliases(Locale loc) { + if (langAliasesMap.isEmpty()) { + langAliasesMap = baseMetaInfo.getLanguageAliasMap(); + } + Locale locale = langAliasesCache.get(loc); + if (locale == null) { + String locTag = loc.toLanguageTag(); + Locale aliasLocale = langAliasesMap.containsKey(locTag) + ? Locale.forLanguageTag(langAliasesMap.get(locTag)) : loc; + langAliasesCache.putIfAbsent(loc, aliasLocale); + return aliasLocale; + } else { + return locale; + } + } + @Override protected Set<String> createLanguageTagSet(String category) { // Assume all categories support the same set as AvailableLocales // in CLDR adapter. category = "AvailableLocales";
*** 173,183 **** } // Implementation of ResourceBundleBasedAdapter @Override public List<Locale> getCandidateLocales(String baseName, Locale locale) { ! List<Locale> candidates = super.getCandidateLocales(baseName, locale); return applyParentLocales(baseName, candidates); } private List<Locale> applyParentLocales(String baseName, List<Locale> candidates) { // check irregular parents --- 195,205 ---- } // Implementation of ResourceBundleBasedAdapter @Override public List<Locale> getCandidateLocales(String baseName, Locale locale) { ! List<Locale> candidates = super.getCandidateLocales(baseName, applyAliases(locale)); return applyParentLocales(baseName, candidates); } private List<Locale> applyParentLocales(String baseName, List<Locale> candidates) { // check irregular parents
< prev index next >