aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/locale.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux/locale.lux')
-rw-r--r--stdlib/source/library/lux/locale.lux45
1 files changed, 45 insertions, 0 deletions
diff --git a/stdlib/source/library/lux/locale.lux b/stdlib/source/library/lux/locale.lux
new file mode 100644
index 000000000..381938c74
--- /dev/null
+++ b/stdlib/source/library/lux/locale.lux
@@ -0,0 +1,45 @@
+(.module:
+ [library
+ [lux #*
+ [abstract
+ [equivalence (#+ Equivalence)]
+ ["." hash (#+ Hash)]]
+ [data
+ ["." maybe ("#\." functor)]
+ ["." text
+ ["%" format (#+ format)]
+ ["." encoding (#+ Encoding)]]]
+ [type
+ abstract]]]
+ [/
+ ["." language (#+ Language)]
+ ["." territory (#+ Territory)]])
+
+(abstract: #export Locale
+ Text
+
+ (def: territory_separator "_")
+ (def: encoding_separator ".")
+
+ (def: #export (locale language territory encoding)
+ (-> Language (Maybe Territory) (Maybe Encoding) Locale)
+ (:abstraction (format (language.code language)
+ (|> territory
+ (maybe\map (|>> territory.long_code (format ..territory_separator)))
+ (maybe.default ""))
+ (|> encoding
+ (maybe\map (|>> encoding.name (format ..encoding_separator)))
+ (maybe.default "")))))
+
+ (def: #export code
+ (-> Locale Text)
+ (|>> :representation))
+
+ (def: #export hash
+ (Hash Locale)
+ (\ hash.functor map ..code text.hash))
+
+ (def: #export equivalence
+ (Equivalence Locale)
+ (\ ..hash &equivalence))
+ )