ICU4N
ICU4N copied to clipboard
Complete UCultureInfo Implementation
In #3, a UCutureInfo
type was created to replace the ICU4J ULocale
type. The main goals for doing this are:
- To provide a similar API as the
CultureInfo
class - To provide a way to set the culture/default culture of the current thread
- To fill gaps in behavior between ICU and the .NET platform
We managed to get a prototype in place, but there are still some remaining tasks and research to complete.
Known Issues
- [ ]
TwoLetterISOLanguageName/GetTwoLetterISOLanguageName
returnsnull
for invariant culture, which is different than the documented behavior of ICU4J (at least for the 3 letter language), which is to return empty string. In .NET, the behavior is to return the string"iv"
. - [ ] The
Parent
property behaves differently in than the .NET platform. In ICU, the script tag is not considered as part of the fallback behavior, but in .NET it is (i.e.uz_Cyrl_UZ
falls back touz_Cyrl
in .NET, but in ICU it falls back touz
). TheAcceptLanguage
overloads ofUCultureInfo
depend on the current behavior for the tests to pass. For now,Parent
has been marked internal until this can be addressed. - [ ] The default behavior of
CurrentCulture
andCurrentUICulture
when not explicitly set is to track the properties of theCultureInfo.CurrentCulture
andCultureInfo.CurrentUICulture
. So, when either of the latter changes, the former are automatically updated to the nearest corresponding culture. If set explicitly, this tracking stops and the culture that is set is used instead. However, once set there is currently no way to "unset"UCultureInfo.CurrentCulture
orUCultureInfo.CurrentUICulture
to get back to the original tracking behavior. - [ ] The
ULocale
class in ICU4J was immutable and itsClone
method simply returned itself. However, in .NETUCultureInfo
was designed to be mutable unless it is wrapped using theReadOnly
method. For now,UCultureInfo
is immutable and markedsealed
so the behavior cannot be changed. - [ ] Since LCID is not available in the CLDR data and is deprecated, the property has been commented out and none of the method overloads or constructors that utilize it have been added.
- [ ] The
Name
property effectively returns the base name in ICU4J. They are similar, however, in .NET they are typically delimited by hyphen and in ICU they are delimited by underscore. Through some limited testing, it appears bothUCultureInfo
andCultureInfo
accept either format. More research is required to determine whether changing to the .NET convention makes sense. - [ ] Lack of caching. In ICU4J, static properties for the most commonly used cultures (to match the JDK). In .NET, there are no such properties, but there are methods available to provide read-only cached cultures.
Missing Members of CultureInfo
The following members of CultureInfo
are not yet present in UCultureInfo
.
Properties
- [ ]
Calendar
- NOTE: ICU4J has its own calendars that are not ported and not planned for the current release - [ ]
CompareInfo
- This is the equivalent of theCollator
class in ICU4J, however the API is more extensible in ICU4J and custom sort rules can be defined. It may not make sense to merge the two. - [ ]
DateTimeFormat
- [ ]
IsReadOnly
- [ ]
KeyboardLayoutId
- [ ]
LCID
- [x]
NumberFormat
- Added in #46. - [ ]
OptionalCalendars
- [ ]
Parent
- Marked internal, since the behavior differs from .NET (see above) - [ ]
TextInfo
- Although ICU has properties that make sense to put here, the constructor is internal - [ ]
ThreeLetterWindowsLanguageName
- [ ]
UseUserOverride
Methods
- [ ]
public static UCultureInfo CreateSpecificCulture(string name)
- [ ]
public UCultureInfo GetConsoleFallbackUICulture()
- [ ]
public static UCultureInfo GetCultureInfo(string name)
- [ ]
public static UCultureInfo GetCultureInfo(int culture)
- [ ]
public static UCultureInfo GetCultureInfo(string name, string altName)
- This one seems to be a duplicate of passing the keyword (i.e.@collation=phonebook
), but in ICU4N, there is currently no culture cache. - [x]
public virtual object GetFormat(Type formatType)
- Added in #46. - [x]
public static UCultureInfo ReadOnly(UCultureInfo ci)
- Added in #46.
Missing Members of ULocale
Properties
- [ ]
CharacterOrientation
- Marked internal, since the logical place to put it would be onTextInfo
- [ ]
LineOrientation
- Marked internal, since the logical place to put it would be onTextInfo
- [ ]
IsRightToLeft
- Marked internal, since the logical place to put it would be onTextInfo
API Documentation
- [ ] Some of the JavaDocs have yet to be converted and other members (including the main class header) have not yet been documented.
UCultureInfoBuilder
- [ ]
UCultureInfoBuilder
ICU4J's ULocale
class has a nested Builder
class that has been de-nested and marked internal. Its purpose is to safely build a locale object while validating the inputs, as the UCultureInfo
class provides no such validation. The CultureInfo
class also doesn't provide validation upon creation, but will throw an exception if the requested culture doesn't exist on the platform.
More research is needed to determine if a similar function exists on the .NET platform so we can correctly map this functionality (which does exist on the Java platform) or whether it makes sense to keep it as is and add it to the public API.