{"action":"created","issue":{"url":"https://api.github.com/repos/ptaoussanis/tower/issues/65","labels_url":"https://api.github.com/repos/ptaoussanis/tower/issues/65/labels{/name}","comments_url":"https://api.github.com/repos/ptaoussanis/tower/issues/65/comments","events_url":"https://api.github.com/repos/ptaoussanis/tower/issues/65/events","html_url":"https://github.com/ptaoussanis/tower/issues/65","id":96648288,"number":65,"title":"Script support for languages","user":{"login":"juhovh","id":262958,"avatar_url":"https://avatars.githubusercontent.com/u/262958?v=3","gravatar_id":"","url":"https://api.github.com/users/juhovh","html_url":"https://github.com/juhovh","followers_url":"https://api.github.com/users/juhovh/followers","following_url":"https://api.github.com/users/juhovh/following{/other_user}","gists_url":"https://api.github.com/users/juhovh/gists{/gist_id}","starred_url":"https://api.github.com/users/juhovh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juhovh/subscriptions","organizations_url":"https://api.github.com/users/juhovh/orgs","repos_url":"https://api.github.com/users/juhovh/repos","events_url":"https://api.github.com/users/juhovh/events{/privacy}","received_events_url":"https://api.github.com/users/juhovh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-22T19:42:15Z","updated_at":"2015-07-24T12:33:39Z","closed_at":null,"body":"I'm writing this on my mobile phone so sorry if I'm describing this too shortly.\r\n\r\nOn JVM languages the language tags are considered to be in format language-region-variant. This is valid, but makes it impossible to select translation based on script, which is kind of a deal breaker for me.\r\n\r\nTo give an example, we could use Serbian language. There are versions sr-Latn-RS (Serbian with latin script in Serbia), sr-Cyrl-RS (Serbian with cyrillic script in Serbia), sr-Latn-MN (Serbian with latin script in Montenegro), sr-Cyrl-MN (Serbian with cyrillic script in Montenegro). There is currently no way of providing script information to the library.\r\n\r\nAnother example is Chinese, where zh-Hans (simplified Chinese) is used in mainland and Singapore, whereas zh-Hant is used in Taiwan and Hong Kong. It would be really useful to have generic localizations for simplified and traditional Chinese and some country specific localizations for example for Taiwan and Singapore.\r\n\r\nNow there are simple fixes and more complicated fixes, the most simple would be to require the language tags to be in form language-script-region-variant, but that would break backwards compatibility. The more complicated version would require regexps and/or parsing etc. Which version you would like to have a pull request of?"},"comment":{"url":"https://api.github.com/repos/ptaoussanis/tower/issues/comments/124505541","html_url":"https://github.com/ptaoussanis/tower/issues/65#issuecomment-124505541","issue_url":"https://api.github.com/repos/ptaoussanis/tower/issues/65","id":124505541,"user":{"login":"juhovh","id":262958,"avatar_url":"https://avatars.githubusercontent.com/u/262958?v=3","gravatar_id":"","url":"https://api.github.com/users/juhovh","html_url":"https://github.com/juhovh","followers_url":"https://api.github.com/users/juhovh/followers","following_url":"https://api.github.com/users/juhovh/following{/other_user}","gists_url":"https://api.github.com/users/juhovh/gists{/gist_id}","starred_url":"https://api.github.com/users/juhovh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juhovh/subscriptions","organizations_url":"https://api.github.com/users/juhovh/orgs","repos_url":"https://api.github.com/users/juhovh/repos","events_url":"https://api.github.com/users/juhovh/events{/privacy}","received_events_url":"https://api.github.com/users/juhovh/received_events","type":"User","site_admin":false},"created_at":"2015-07-24T12:33:39Z","updated_at":"2015-07-24T12:33:39Z","body":"Hi,\r\n\r\nSorry for not being clear enough in my description, I'll try to be short and describe my use case better.\r\n\r\nI have a system where I have a valid IETF BCP 47 locale in my database for each user. I want to use this locale for formatting both translations and JVM-dependent localization features. If we take `zh-Hans-CN` as an example, I can use it just fine for translations, but if I try to use it for localization features the following happens:\r\n\r\n```\r\n=> (tower/fmt-str :zh-Hans-CN \"%f\" 5.5)\r\nExceptionInfo Invalid locale: :zh-Hans-CN  clojure.core/ex-info (core.clj:4403)\r\n```\r\n\r\nThis is not nice, because `zh-Hans-CN` is a perfectly valid locale according to best current practices. (hence BCP)\r\n\r\nWhat I would really like to have as a first step would be something like the following:\r\n\r\n```\r\ndiff --git a/src/taoensso/tower.cljx b/src/taoensso/tower.cljx\r\nindex 2abb09d..933decd 100644\r\n--- a/src/taoensso/tower.cljx\r\n+++ b/src/taoensso/tower.cljx\r\n@@ -7,7 +7,7 @@\r\n                   [taoensso.encore :as encore]\r\n                   [taoensso.timbre :as timbre]\r\n                   [taoensso.tower.utils :as utils :refer (defmem- defmem-*)])\r\n-  #+clj (:import  [java.util Date Locale TimeZone Formatter]\r\n+  #+clj (:import  [java.util Date Locale Locale$Builder TimeZone Formatter IllformedLocaleException]\r\n                   [java.text Collator NumberFormat DateFormat])\r\n   #+cljs (:require-macros [taoensso.encore :as encore]\r\n                           [taoensso.tower  :as tower-macros])\r\n@@ -67,11 +67,16 @@\r\n         (make-Locale (.getLanguage ^Locale loc)))\r\n \r\n       :else\r\n-      (let [loc-parts (str/split (name loc) #\"[-_]\")]\r\n-        (all-Locales\r\n-          (if-not lang-only?\r\n-            (apply make-Locale loc-parts)\r\n-            (make-Locale (first loc-parts))))))))\r\n+      (try\r\n+        (let [loc-obj (.build (.setLanguageTag (Locale$Builder.) (name loc)))]\r\n+          (if-not lang-only? loc-obj\r\n+            (make-Locale (.getLanguage ^Locale loc-obj))))\r\n+        (catch IllformedLocaleException e\r\n+          (let [loc-parts (str/split (name loc) #\"[_]\")]\r\n+            (all-Locales\r\n+              (if-not lang-only?\r\n+                (apply make-Locale loc-parts)\r\n+                (make-Locale (first loc-parts))))))))))\r\n \r\n #+clj\r\n (def jvm-locale\r\n```\r\n\r\nThis would support all BCP 47 locales and try to fall back to the old legacy way of handling locales. Notice that I removed `-` from the regex because I think it would be much nicer to have all locale names separated by dash to be well formed BCP 47 names.\r\n\r\nWhat would be nice in the long run would be something like what .NET does as explained in https://msdn.microsoft.com/en-us/library/vstudio/dd997383(v=vs.100).aspx\r\n\r\n```\r\nThe parent chain of the Chinese cultures now includes the root Chinese culture. The following examples show the complete parent chain for two of the Chinese specific cultures:\r\n\r\nzh-CN → zh-CHS → zh-Hans → zh → Invariant\r\nzh-TW → zh-CHT → zh-Hant → zh → Invariant\r\n````\r\n\r\nSo the system should know that simplified Chinese is used in mainland China and fall back to zh-Hans if zh-CN is used. But it seems that the JVM doesn't support this either and leaves it to the implementation to handle correct mappings, so I think it's out of scope of tower.\r\n\r\nDid this clarify my point of script support any better?"}}