Crates.io | locale_config |
lib.rs | locale_config |
version | 0.3.0 |
source | src |
created_at | 2016-12-28 02:47:42.861179 |
updated_at | 2019-08-22 18:42:42.066796 |
description | Maintains locale preferences for process and thread and initialises them by inspecting the system for user preference. |
homepage | |
repository | https://github.com/rust-locale/locale_config/ |
max_upload_size | |
id | 7806 |
size | 73,626 |
locale_config
Remembers locale configuration per-thread and per-process and initializes the values by inspecting the system for user preferences.
You can depend on this library by adding locale_config
to your Cargo dependencies:
[dependencies]
locale_config = "*"
Usually it is not recommended to depend on *
, but in this case it is
important that incompatible version requirements don't cause multiple
versions to be pulled in the final binary, so I do recommend it here and
promise I will maintain good compatibility. Just please don't add traits to
the types defined here to avoid conflicts with potential future methods.
Usually you want to use this indirectly via a localization crate like
locale
. However if you need to work with the identifier itself, or you need
to override it, use
Locale::current()
to find what you should be using at any given point in the application,
Locale::set_current()
to override it for current thread and
Locale::set_global_default()
to override it for new threads.
In case you need to access the initial value, you'll find it under
Locale::user_default()
The value may contain language tags specific for various localization
aspects, called categories, and fallbacks. The Locale::tags_for
method will
take care of selecting relevant tags for you. For preferred language of
translations, use
Locale::current().tags_for("messages")
For formatting, use categories "numeric"
for numbers, "time"
for date and
time and "monetary"
for money amounts. And use "collate"
for collation.
Note that this crate does not itself provide any translation, formatting nor
collation functionality. Formatting and collation will be provided by
locale
crate, translation has multiple available implementations.
See full documentation on or github.
Unix: Using the POSIX standard environment variables LANG
, LC_*
and
LANGUAGES
. The variables are recognized on all systems and take
precedence on most of them.
Windows: Vista and newer
GetUserPreferredUILanguages
is only available for desktop, but
not store applications. Store applications should have equivalent
functionality, but I didn't try accessing it from Rust yet.OS X: Reads setting from NSLocale
, can be overridden by setting the
Unix environment variables.
CGI: The HTTP_ACCEPT_LANGUAGE
environment variable is used if
detected. Hopefully it is specific enough to the CGI environment that it
can be used whenever detected.
NSLocale
.
Thanks Sophie Tauchert (@999eagle).