Compare commits

...

2 Commits

5 changed files with 2014 additions and 27 deletions

605
Cargo.lock generated
View File

@ -483,6 +483,16 @@ dependencies = [
"system-deps", "system-deps",
] ]
[[package]]
name = "calendrical_calculations"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dfe3bc6a50b4667fafdb6d9cf26731c5418c457e317d8166c972014facf9a5d"
dependencies = [
"core_maths",
"displaydoc",
]
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.83" version = "1.0.83"
@ -692,6 +702,15 @@ version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]]
name = "core_maths"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3b02505ccb8c50b0aa21ace0fc08c3e53adebd4e58caa18a36152803c7709a3"
dependencies = [
"libm",
]
[[package]] [[package]]
name = "cpufeatures" name = "cpufeatures"
version = "0.2.11" version = "0.2.11"
@ -1117,6 +1136,17 @@ dependencies = [
"tokio", "tokio",
] ]
[[package]]
name = "fixed_decimal"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbc7fdec9d7f6671a3ebb3282c969962aba67c49f6abac5311959b65cafabc10"
dependencies = [
"displaydoc",
"smallvec",
"writeable",
]
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.0.28" version = "1.0.28"
@ -2020,6 +2050,422 @@ dependencies = [
"libadwaita", "libadwaita",
] ]
[[package]]
name = "icu"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21be1c98fbdb29fff7e34b2939a4f30dad330d4cc20f7be1b3956e21032f67ba"
dependencies = [
"icu_calendar",
"icu_casemap",
"icu_collator",
"icu_collections",
"icu_compactdecimal",
"icu_datetime",
"icu_decimal",
"icu_displaynames",
"icu_list",
"icu_locid",
"icu_locid_transform",
"icu_normalizer",
"icu_plurals",
"icu_properties",
"icu_provider",
"icu_relativetime",
"icu_segmenter",
"icu_timezone",
]
[[package]]
name = "icu_calendar"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7eb932a690c92f87955e923106181ee0d5682e688ff37fb5c7b296e1fe806edb"
dependencies = [
"calendrical_calculations",
"displaydoc",
"icu_calendar_data",
"icu_locid",
"icu_locid_transform",
"icu_provider",
"tinystr",
"writeable",
"zerovec",
]
[[package]]
name = "icu_calendar_data"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22aec7d032735d9acb256eeef72adcac43c3b7572f19b51576a63d664b524ca2"
[[package]]
name = "icu_casemap"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7988d4f2655012592ac5b027722a93fbe12ff2a86d3e0f9ae686aedba0984f5e"
dependencies = [
"displaydoc",
"icu_casemap_data",
"icu_collections",
"icu_locid",
"icu_properties",
"icu_provider",
"writeable",
"zerovec",
]
[[package]]
name = "icu_casemap_data"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f36409fb8ce6f87c408310d87396ac471cc7320e007e648814c607c60fe77cc5"
[[package]]
name = "icu_collator"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a2a45056e541cffde068f5c81ac1c0503b9ee2a4b967546422e509c5c653750"
dependencies = [
"displaydoc",
"icu_collator_data",
"icu_collections",
"icu_locid",
"icu_locid_transform",
"icu_normalizer",
"icu_properties",
"icu_provider",
"smallvec",
"utf16_iter",
"utf8_iter",
"zerovec",
]
[[package]]
name = "icu_collator_data"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39774016c5b9ad006941f3196fea83ade662d9167eb573111c8f4cc9593e2999"
[[package]]
name = "icu_collections"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "137d96353afc8544d437e8a99eceb10ab291352699573b0de5b08bda38c78c60"
dependencies = [
"displaydoc",
"yoke",
"zerofrom",
"zerovec",
]
[[package]]
name = "icu_compactdecimal"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d3c22da90659121ae1e38bd0fb378d15179c820f56a0c278032fb4eb5a0ca60"
dependencies = [
"displaydoc",
"fixed_decimal",
"icu_compactdecimal_data",
"icu_decimal",
"icu_locid_transform",
"icu_plurals",
"icu_provider",
"writeable",
"zerovec",
]
[[package]]
name = "icu_compactdecimal_data"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53eaf4902ee2e804f2583611722f6961fe85f31eab7ec790f47dde2d1cd494fb"
[[package]]
name = "icu_datetime"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1508c7ed627cc0b031c81203eb98f34433e24b32b39d5b2c0238e4962a00957d"
dependencies = [
"displaydoc",
"either",
"fixed_decimal",
"icu_calendar",
"icu_datetime_data",
"icu_decimal",
"icu_locid",
"icu_locid_transform",
"icu_plurals",
"icu_provider",
"icu_timezone",
"smallvec",
"tinystr",
"writeable",
"zerovec",
]
[[package]]
name = "icu_datetime_data"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6abc569cb4ee80b30707566f05c5c9ed4bed765f91ce41e7f5a37c5e6a75b3f"
[[package]]
name = "icu_decimal"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf994f9ed8061c17bb313f28fba6cffc736f0a16c7fab827efc9b73fd3f7778"
dependencies = [
"displaydoc",
"fixed_decimal",
"icu_decimal_data",
"icu_locid",
"icu_locid_transform",
"icu_provider",
"writeable",
]
[[package]]
name = "icu_decimal_data"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df2de3548316b697c70f30dec1395c9212db09df1d86a27624ee24872b71326c"
[[package]]
name = "icu_displaynames"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "726c0d83ff52f05907275f39e5bb7949a92fa3d09538de60cf73ccf8ee89a613"
dependencies = [
"icu_displaynames_data",
"icu_locid",
"icu_locid_transform",
"icu_provider",
"tinystr",
"zerovec",
]
[[package]]
name = "icu_displaynames_data"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af40e6b723e5e6d9359cf0bb4e4ed6dfb9d6ab16b73b5c82b61f947e88bb30f6"
[[package]]
name = "icu_list"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe6c04ec71ad1bacdbfb47164d4801f80a0533d9340f94f1a880f521eff59f54"
dependencies = [
"displaydoc",
"icu_list_data",
"icu_locid_transform",
"icu_provider",
"regex-automata 0.2.0",
"writeable",
]
[[package]]
name = "icu_list_data"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f6afcf7a9a7fedece70b7f17d7a7ecdfb8df145d37ae46d0277cd1e3932532"
[[package]]
name = "icu_locid"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c0aa2536adc14c07e2a521e95512b75ed8ef832f0fdf9299d4a0a45d2be2a9d"
dependencies = [
"displaydoc",
"litemap",
"tinystr",
"writeable",
"zerovec",
]
[[package]]
name = "icu_locid_transform"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c17d8f6524fdca4471101dd71f0a132eb6382b5d6d7f2970441cb25f6f435a"
dependencies = [
"displaydoc",
"icu_locid",
"icu_locid_transform_data",
"icu_provider",
"tinystr",
"zerovec",
]
[[package]]
name = "icu_locid_transform_data"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "545c6c3e8bf9580e2dafee8de6f9ec14826aaf359787789c7724f1f85f47d3dc"
[[package]]
name = "icu_normalizer"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c183e31ed700f1ecd6b032d104c52fe8b15d028956b73727c97ec176b170e187"
dependencies = [
"displaydoc",
"icu_collections",
"icu_normalizer_data",
"icu_properties",
"icu_provider",
"smallvec",
"utf16_iter",
"utf8_iter",
"write16",
"zerovec",
]
[[package]]
name = "icu_normalizer_data"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22026918a80e6a9a330cb01b60f950e2b4e5284c59528fd0c6150076ef4c8522"
[[package]]
name = "icu_plurals"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37d807b123eb2a9ae8f12080fb8cce479f5c8a761fba0bb5ab52da6dd5e31a03"
dependencies = [
"displaydoc",
"fixed_decimal",
"icu_locid",
"icu_locid_transform",
"icu_plurals_data",
"icu_provider",
"zerovec",
]
[[package]]
name = "icu_plurals_data"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3acd5f1f2f988ed2dae9316c3d3560dfe4e03a7516d142b4b89b92252ada41a"
[[package]]
name = "icu_properties"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "976e296217453af983efa25f287a4c1da04b9a63bf1ed63719455068e4453eb5"
dependencies = [
"displaydoc",
"icu_collections",
"icu_locid_transform",
"icu_properties_data",
"icu_provider",
"tinystr",
"zerovec",
]
[[package]]
name = "icu_properties_data"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6a86c0e384532b06b6c104814f9c1b13bcd5b64409001c0d05713a1f3529d99"
[[package]]
name = "icu_provider"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba58e782287eb6950247abbf11719f83f5d4e4a5c1f2cd490d30a334bc47c2f4"
dependencies = [
"displaydoc",
"icu_locid",
"icu_provider_macros",
"stable_deref_trait",
"tinystr",
"writeable",
"yoke",
"zerofrom",
"zerovec",
]
[[package]]
name = "icu_provider_macros"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2abdd3a62551e8337af119c5899e600ca0c88ec8f23a46c60ba216c803dcf1a"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
]
[[package]]
name = "icu_relativetime"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47825312a5eb0790bad7b718fa8d41a8ea1e0ba597b4f7bb84bcfe97d7fc5aba"
dependencies = [
"displaydoc",
"fixed_decimal",
"icu_decimal",
"icu_locid_transform",
"icu_plurals",
"icu_provider",
"icu_relativetime_data",
"writeable",
"zerovec",
]
[[package]]
name = "icu_relativetime_data"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05b55cc15ea8981fbba78e9347d0c4003d4490c85f76e9adc7f270290046cae8"
[[package]]
name = "icu_segmenter"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2dc1e8f4ba33a6a4956770ac5c08570f255d6605519fb3a859a0c0a270a2f8f"
dependencies = [
"core_maths",
"displaydoc",
"icu_collections",
"icu_locid",
"icu_provider",
"icu_segmenter_data",
"utf8_iter",
"zerovec",
]
[[package]]
name = "icu_segmenter_data"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3673d6698dcffce08cfe8fc5da3c11c3f2c663d5d6137fd58ab2cbf44235ab46"
[[package]]
name = "icu_timezone"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b35aabe571a7c653c0f543ff1512b8a1b2ad481cfa24b3d25115298d2ff3b50f"
dependencies = [
"displaydoc",
"icu_calendar",
"icu_locid",
"icu_provider",
"icu_timezone_data",
"tinystr",
"zerotrie",
"zerovec",
]
[[package]]
name = "icu_timezone_data"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ceee21e181cce2ab44e95923da6b3418df75369f570df82264c29c51ca398d4"
[[package]] [[package]]
name = "idna" name = "idna"
version = "0.1.5" version = "0.1.5"
@ -2262,6 +2708,19 @@ dependencies = [
"log 0.4.20", "log 0.4.20",
] ]
[[package]]
name = "l10n"
version = "0.1.0"
dependencies = [
"chrono",
"chrono-tz",
"fluent-ergonomics",
"icu",
"icu_locid",
"icu_provider",
"sys-locale",
]
[[package]] [[package]]
name = "language-tags" name = "language-tags"
version = "0.2.2" version = "0.2.2"
@ -2350,6 +2809,12 @@ version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456"
[[package]]
name = "litemap"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9d642685b028806386b2b6e75685faadd3eb65a85fff7df711ce18446a422da"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.11" version = "0.4.11"
@ -3364,10 +3829,19 @@ checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
"regex-automata", "regex-automata 0.4.3",
"regex-syntax", "regex-syntax",
] ]
[[package]]
name = "regex-automata"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9368763f5a9b804326f3af749e16f9abf378d227bcdee7634b13d8f17793782"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "regex-automata" name = "regex-automata"
version = "0.4.3" version = "0.4.3"
@ -4015,6 +4489,12 @@ dependencies = [
"urlencoding", "urlencoding",
] ]
[[package]]
name = "stable_deref_trait"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]] [[package]]
name = "stringprep" name = "stringprep"
version = "0.1.4" version = "0.1.4"
@ -4060,6 +4540,26 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "synstructure"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
]
[[package]]
name = "sys-locale"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e801cf239ecd6ccd71f03d270d67dd53d13e90aab208bf4b8fe4ad957ea949b0"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "system-configuration" name = "system-configuration"
version = "0.5.1" version = "0.5.1"
@ -4229,6 +4729,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83c02bf3c538ab32ba913408224323915f4ef9a6d61c0e85d493f355921c0ece" checksum = "83c02bf3c538ab32ba913408224323915f4ef9a6d61c0e85d493f355921c0ece"
dependencies = [ dependencies = [
"displaydoc", "displaydoc",
"zerovec",
] ]
[[package]] [[package]]
@ -4611,6 +5112,18 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
name = "utf16_iter"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246"
[[package]]
name = "utf8_iter"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]] [[package]]
name = "utf8parse" name = "utf8parse"
version = "0.2.1" version = "0.2.1"
@ -5034,6 +5547,42 @@ dependencies = [
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
[[package]]
name = "write16"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936"
[[package]]
name = "writeable"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dad7bb64b8ef9c0aa27b6da38b452b0ee9fd82beaf276a87dd796fb55cbae14e"
[[package]]
name = "yoke"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65e71b2e4f287f467794c671e2b8f8a5f3716b3c829079a1c44740148eff07e4"
dependencies = [
"serde 1.0.193",
"stable_deref_trait",
"yoke-derive",
"zerofrom",
]
[[package]]
name = "yoke-derive"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e6936f0cce458098a201c245a11bef556c6a0181129c7034d10d76d1ec3a2b8"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
"synstructure",
]
[[package]] [[package]]
name = "zerocopy" name = "zerocopy"
version = "0.7.31" version = "0.7.31"
@ -5054,12 +5603,66 @@ dependencies = [
"syn 2.0.48", "syn 2.0.48",
] ]
[[package]]
name = "zerofrom"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "655b0814c5c0b19ade497851070c640773304939a6c0fd5f5fb43da0696d05b7"
dependencies = [
"zerofrom-derive",
]
[[package]]
name = "zerofrom-derive"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6a647510471d372f2e6c2e6b7219e44d8c574d24fdc11c610a61455782f18c3"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
"synstructure",
]
[[package]] [[package]]
name = "zeroize" name = "zeroize"
version = "1.7.0" version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d"
[[package]]
name = "zerotrie"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0594125a0574fb93059c92c588ab209cc036a23d1baeb3410fa9181bea551a0"
dependencies = [
"displaydoc",
"yoke",
"zerofrom",
]
[[package]]
name = "zerovec"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eff4439ae91fb5c72b8abc12f3f2dbf51bd27e6eadb9f8a5bc8898dddb0e27ea"
dependencies = [
"yoke",
"zerofrom",
"zerovec-derive",
]
[[package]]
name = "zerovec-derive"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b4e5997cbf58990550ef1f0e5124a05e47e1ebd33a84af25739be6031a62c20"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
]
[[package]] [[package]]
name = "zune-inflate" name = "zune-inflate"
version = "0.2.54" version = "0.2.54"

1185
Cargo.nix

File diff suppressed because it is too large Load Diff

View File

@ -20,6 +20,7 @@ members = [
"ifc", "ifc",
"kifu/core", "kifu/core",
"kifu/gtk", "kifu/gtk",
"l10n",
"memorycache", "memorycache",
"nom-training", "nom-training",
"result-extended", "result-extended",

15
l10n/Cargo.toml Normal file
View File

@ -0,0 +1,15 @@
[package]
name = "l10n"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
chrono = { version = "0.4" }
chrono-tz = { version = "0.8" }
fluent-ergonomics = { path = "../fluent-ergonomics" }
icu = { version = "1" }
icu_locid = { version = "1" }
icu_provider = { version = "1" }
sys-locale = { version = "0.3" }

235
l10n/src/lib.rs Normal file
View File

@ -0,0 +1,235 @@
use std::ops::Deref;
use chrono::{Datelike, FixedOffset, NaiveDate, TimeZone, Timelike};
use chrono_tz::{OffsetName, Tz};
use icu::{
datetime::options::length,
timezone::{CustomTimeZone, GmtOffset},
};
use icu_locid::{locale, Locale};
use icu_provider::DataLocale;
use std::str::FromStr;
use sys_locale::get_locale;
#[derive(Clone, Debug)]
pub struct L10N {
locale: Locale,
zone: chrono_tz::Tz,
}
impl Default for L10N {
fn default() -> Self {
let lc = get_locale().unwrap();
let locale = Locale::try_from_bytes(lc.as_bytes()).unwrap();
let zone = chrono_tz::UTC;
Self { locale, zone }
}
}
impl L10N {
fn set_locale(&mut self, locale: String) {
let locale = Locale::try_from_bytes(locale.as_bytes()).unwrap();
self.locale = locale;
}
fn set_timezone(&mut self, zone: Tz) {
self.zone = zone;
}
// Need to take a message and turn it into a string in the current language. Except I don't
// know yet what form the message should take. Forming an adapter around fluent_ergonomics or
// even around fluent itself. I would want for the message to be statically typed, but then I
// don't know what can be the data type that gets passed in here.
fn format_message(&self) -> String {
unimplemented!()
}
fn format_date_time_utc(
&self,
time: DateTime,
date_style: length::Date,
time_style: length::Time,
) -> String {
let time: DateTime = time.with_timezone(&chrono_tz::UTC).into();
let options = length::Bag::from_date_time_style(date_style, time_style);
let formatter = icu::datetime::DateTimeFormatter::try_new(
&DataLocale::from(&self.locale),
options.into(),
)
.unwrap();
let icu_time: icu::calendar::DateTime<icu::calendar::Gregorian> = time.into();
formatter.format_to_string(&icu_time.to_any()).unwrap()
}
fn format_date_time_local(
&self,
time: DateTime,
date_style: length::Date,
time_style: length::Time,
) -> String {
let time: DateTime = time.with_timezone(&self.zone).into();
let options = length::Bag::from_date_time_style(date_style, time_style);
let formatter = icu::datetime::DateTimeFormatter::try_new(
&DataLocale::from(&self.locale),
options.into(),
)
.unwrap();
let icu_time: icu::calendar::DateTime<icu::calendar::Gregorian> = time.into();
formatter.format_to_string(&icu_time.to_any()).unwrap()
}
/*
* I have been unable to get from a chrono_tz::Tz to an ICU timezone. I have tried a variety of
* parsers on the CustomTimeZone object. I have not researched the data provider to see what is
* available there. The ZoneID for the reference date is US/Mountain, and the abbreviation is
* MST. I'll want to get to a CustomTimeZone so that the formatter can render MST or Mountain
* Standard Time or something similar.
fn format_date_time_tz(
&self,
time: DateTime,
date_style: length::Date,
time_style: length::Time,
) -> String {
let options = length::Bag::from_date_time_style(date_style, time_style);
let formatter = icu::datetime::ZonedDateTimeFormatter::try_new(
&DataLocale::from(&self.locale),
options.into(),
Default::default(),
)
.unwrap();
let icu_time: icu::calendar::DateTime<icu::calendar::Gregorian> = time.into();
let any = icu_time.to_any();
println!("{:?}", time.offset());
let zone_id: String = time.offset().abbreviation().to_owned();
println!("{:?}", zone_id);
let zone_id = icu::timezone::TimeZoneBcp47Id::from_str(&zone_id).unwrap();
let zone: CustomTimeZone = CustomTimeZone {
gmt_offset: None,
time_zone_id: Some(zone_id),
/*
icu::timezone::TimeZoneBcp47Id::from_str(time.offset().tz_id().parse().unwrap())
.unwrap(),
*/
metazone_id: None,
zone_variant: None,
};
formatter.format_to_string(&any, &zone).unwrap()
}
*/
fn format_date(
&self,
time: NaiveDate,
date_style: length::Date,
time_style: length::Time,
) -> String {
unimplemented!()
}
fn format_f64(&self, value: f64) -> String {
unimplemented!()
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
struct DateTime(chrono::DateTime<Tz>);
impl Deref for DateTime {
type Target = chrono::DateTime<Tz>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl From<chrono::DateTime<Tz>> for DateTime {
fn from(time: chrono::DateTime<Tz>) -> Self {
Self(time)
}
}
impl From<DateTime> for icu::calendar::DateTime<icu::calendar::Gregorian> {
fn from(time: DateTime) -> Self {
// SAFETY: these unwraps should be safe since chrono dates are already valid Gregorian
// dates
icu::calendar::DateTime::try_new_gregorian_datetime(
time.year(),
time.month().try_into().unwrap(),
time.day().try_into().unwrap(),
time.hour().try_into().unwrap(),
time.minute().try_into().unwrap(),
time.second().try_into().unwrap(),
)
.unwrap()
}
}
#[cfg(test)]
mod tests {
use super::*;
fn reftime() -> DateTime {
NaiveDate::from_ymd_opt(2006, 1, 2)
.unwrap()
.and_hms_opt(3, 4, 5)
.unwrap()
.and_local_timezone(Tz::US__Mountain)
.unwrap()
.into()
}
#[test]
fn it_formats_a_time_in_utc() {
let mut l10n = L10N::default();
// Make sure we know the locale before the test begins. Some systems, such as my own, are
// not actually in English.
l10n.set_locale("en-US".to_owned());
l10n.set_timezone(chrono_tz::US::Eastern);
let now = reftime();
// 202f is the code-point for a narrow non-breaking space. Presumably this is used in
// particular to ensure that the am/pm marker doesn't get split off from the time
assert_eq!(
l10n.format_date_time_utc(now.clone(), length::Date::Long, length::Time::Medium),
"January 2, 2006, 10:04:05\u{202f}AM"
);
l10n.set_locale("eo-EO".to_owned());
assert_eq!(
l10n.format_date_time_utc(now.clone(), length::Date::Long, length::Time::Medium),
"2006-Januaro-02 10:04:05"
);
}
#[test]
fn it_formats_a_time_in_the_current_zone() {
let mut l10n = L10N::default();
// Make sure we know the locale before the test begins. Some systems, such as my own, are
// not actually in English.
l10n.set_locale("en-US".to_owned());
l10n.set_timezone(chrono_tz::US::Eastern);
let now = reftime();
// 202f is the code-point for a narrow non-breaking space. Presumably this is used in
// particular to ensure that the am/pm marker doesn't get split off from the time
assert_eq!(
l10n.format_date_time_local(now.clone(), length::Date::Long, length::Time::Medium),
"January 2, 2006, 5:04:05\u{202f}AM"
);
l10n.set_locale("eo-EO".to_owned());
assert_eq!(
l10n.format_date_time_local(now.clone(), length::Date::Long, length::Time::Medium),
"2006-Januaro-02 05:04:05"
);
}
#[test]
fn it_formats_a_number_according_to_locale() {
unimplemented!()
}
}