Difference between revisions of "Internationalization/locale"

(Windows)
m (Windows: - Adjusted code section)
Line 72: Line 72:
  
 
The code should then look like this:
 
The code should then look like this:
<br> language_id: INTEGER is
+
 
<br> -- `GetUserDefaultLCID' C encapsulation.
+
<code>[eiffel,N]
<br> external
+
language_id: INTEGER is
<br> "C [macro %"windows.h%"] : EIF_STRING"
+
-- `GetUserDefaultLCID' C encapsulation.
<br> -- the macro gives an output of type LCID (is it a string?), ie EIF_STRING needs to be changed accordingly if possible
+
external
<br> alias
+
"C [macro %"windows.h%"] : EIF_STRING"
<br> "GetUserDefaultLCID"
+
-- the macro gives an output of type LCID (is it a string?), ie EIF_STRING needs to be changed accordingly if possible
<br> end
+
alias
 +
"GetUserDefaultLCID"
 +
end
 +
</code>
  
 
== References and useful links ==
 
== References and useful links ==

Revision as of 05:25, 22 June 2006


In computing, locale is a set of parameters that defines the user's language, country and any special variant preferences that the user wants to see in their user interface.

Format of locale on OS's

  • windows (for unmanaged code): hexadecimal code consisting of a language code (lower 10 bits) and culture code (upper bits), aka Locale Identifier (LCID)
  • linux, unix: defined as [language[_territory][.codeset][@modifier]]

Where to find locale

Linux

the environment variable is LANG

here is a list for more specific variables:

Locale category Application
LC_COLLATE Collation of strings (sort order.)
LC_CTYPE Classification and conversion of characters.
LC_MESSAGES Translations of yes and no.
LC_MONETARY Format of monetary values.
LC_NUMERIC Format of non-monetary numeric values.
LC_TIME Date and time formats.
LC_ALL Sets all of the above (overrides all of them.)
LANG Sets all the categories, but can be overridden by the individual locale categories.

Windows

The LCID for "Language for non-Unicode programs" (aka system locale) can be found in the windows registry.
The LCID of "standards and formats" (aka user locale) doesn't seem to be in the registry nor in the environment variables of windows.

How to access to locale

Linux

The function "get" that fetches the language environment variable (LANG) can be found in class SHARED_EXEC_ENVIRONMENT

Windows

In Eiffel there exist a "locale_id" in class WEL_COMPARE_ITEM_STRUCT that uses the macro MAKELCID to get the locale identifier (aka LCID) from the language id. SUBLANGID takes a language id and returns a sublanguage id like SUBLANG_ITALIAN_SWISS. PRIMARYLANGID takes a language id and returns a primary language id like SUBLANG_ITALIAN.


Two solutions:

  • Find out how to get the language id
  • Use the locale id (convenient if SortID is needed)


Notes: Locale id is formed by SortID and LanguageID.
SortID contains info on the language encoding (?) like japanese unicode order, japanese XJIS order, chinese unicode order, chinese BIG5 order,... As one of the predefined LCIDs there is LOCALE_USER_DEFAULT. Problem: what's his hexadecimal code?
Macros for windows are contained in "windows.h".


Found the macro needed: GetUserDefaultLCID()


The code should then look like this:

language_id: INTEGER is
		-- `GetUserDefaultLCID' C encapsulation.
	external
		"C [macro %"windows.h%"] : EIF_STRING"
			-- the macro gives an output of type LCID (is it a string?), ie EIF_STRING needs to be changed accordingly if possible
	alias
		"GetUserDefaultLCID"
	end

References and useful links