logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

README.md (6134B)


  1. # Custom Locale Data
  2. This folder is used to store custom locale data. These custom locale data are
  3. not yet provided by [Unicode Common Locale Data Repository](http://cldr.unicode.org/development/new-cldr-developers)
  4. and hence not provided in [react-intl/locale-data/*](https://github.com/yahoo/react-intl).
  5. The locale data should support [Locale Data APIs](https://github.com/yahoo/react-intl/wiki/API#locale-data-apis)
  6. of the react-intl library.
  7. It is recommended to start your custom locale data from this sample English
  8. locale data ([*](#plural-rules)):
  9. ```javascript
  10. /*eslint eqeqeq: "off"*/
  11. /*eslint no-nested-ternary: "off"*/
  12. export default [
  13. {
  14. locale: "en",
  15. pluralRuleFunction: function(e, a) {
  16. var n = String(e).split("."),
  17. l = !n[1],
  18. o = Number(n[0]) == e,
  19. t = o && n[0].slice(-1),
  20. r = o && n[0].slice(-2);
  21. return a ? 1 == t && 11 != r ? "one" : 2 == t && 12 != r ? "two" : 3 == t && 13 != r ? "few" : "other" : 1 == e && l ? "one" : "other"
  22. },
  23. fields: {
  24. year: {
  25. displayName: "year",
  26. relative: {
  27. 0: "this year",
  28. 1: "next year",
  29. "-1": "last year"
  30. },
  31. relativeTime: {
  32. future: {
  33. one: "in {0} year",
  34. other: "in {0} years"
  35. },
  36. past: {
  37. one: "{0} year ago",
  38. other: "{0} years ago"
  39. }
  40. }
  41. },
  42. month: {
  43. displayName: "month",
  44. relative: {
  45. 0: "this month",
  46. 1: "next month",
  47. "-1": "last month"
  48. },
  49. relativeTime: {
  50. future: {
  51. one: "in {0} month",
  52. other: "in {0} months"
  53. },
  54. past: {
  55. one: "{0} month ago",
  56. other: "{0} months ago"
  57. }
  58. }
  59. },
  60. day: {
  61. displayName: "day",
  62. relative: {
  63. 0: "today",
  64. 1: "tomorrow",
  65. "-1": "yesterday"
  66. },
  67. relativeTime: {
  68. future: {
  69. one: "in {0} day",
  70. other: "in {0} days"
  71. },
  72. past: {
  73. one: "{0} day ago",
  74. other: "{0} days ago"
  75. }
  76. }
  77. },
  78. hour: {
  79. displayName: "hour",
  80. relativeTime: {
  81. future: {
  82. one: "in {0} hour",
  83. other: "in {0} hours"
  84. },
  85. past: {
  86. one: "{0} hour ago",
  87. other: "{0} hours ago"
  88. }
  89. }
  90. },
  91. minute: {
  92. displayName: "minute",
  93. relativeTime: {
  94. future: {
  95. one: "in {0} minute",
  96. other: "in {0} minutes"
  97. },
  98. past: {
  99. one: "{0} minute ago",
  100. other: "{0} minutes ago"
  101. }
  102. }
  103. },
  104. second: {
  105. displayName: "second",
  106. relative: {
  107. 0: "now"
  108. },
  109. relativeTime: {
  110. future: {
  111. one: "in {0} second",
  112. other: "in {0} seconds"
  113. },
  114. past: {
  115. one: "{0} second ago",
  116. other: "{0} seconds ago"
  117. }
  118. }
  119. }
  120. }
  121. }
  122. ]
  123. ```
  124. ## Notes
  125. ### Plural Rules
  126. The function `pluralRuleFunction()` should return the key to proper string of
  127. a plural form(s). The purpose of the function is to provide key of translate
  128. strings of correct plural form according. The different forms are described in
  129. [CLDR's Plural Rules][cldr-plural-rules],
  130. [cldr-plural-rules]: http://cldr.unicode.org/index/cldr-spec/plural-rules
  131. #### Quick Overview on CLDR Rules
  132. Let's take English as an example.
  133. When you describe a number, you can be either describe it as:
  134. * Cardinals: 1st, 2nd, 3rd ... 11th, 12th ... 21st, 22nd, 23nd ....
  135. * Ordinals: 1, 2, 3 ...
  136. In any of these cases, the nouns will reflect the number with singular or plural
  137. form. For example:
  138. * in 0 days
  139. * in 1 day
  140. * in 2 days
  141. The `pluralRuleFunction` receives 2 parameters:
  142. * `e`: a string representation of the number. Such as, "`1`", "`2`", "`2.1`".
  143. * `a`: `true` if this is "cardinal" type of description. `false` for ordinal and other case.
  144. #### How you should write `pluralRuleFunction`
  145. The first rule to write pluralRuleFunction is never translate the output string
  146. into your language. [Plural Rules][cldr-plural-rules] specified you should use
  147. these as the return values:
  148. * "`zero`"
  149. * "`one`" (singular)
  150. * "`two`" (dual)
  151. * "`few`" (paucal)
  152. * "`many`" (also used for fractions if they have a separate class)
  153. * "`other`" (required—general plural form—also used if the language only has a single form)
  154. Again, we'll use English as the example here.
  155. Let's read the `return` statement in the pluralRuleFunction above:
  156. ```javascript
  157. return a ? 1 == t && 11 != r ? "one" : 2 == t && 12 != r ? "two" : 3 == t && 13 != r ? "few" : "other" : 1 == e && l ? "one" : "other"
  158. ```
  159. This nested ternary is hard to read. It basically means:
  160. ```javascript
  161. // e: the number variable to examine
  162. // a: "true" if cardinals
  163. // l: "true" if the variable e has nothin after decimal mark (e.g. "1.0" would be false)
  164. // o: "true" if the variable e is an integer
  165. // t: the "ones" of the number. e.g. "3" for number "9123"
  166. // r: the "ones" and "tens" of the number. e.g. "23" for number "9123"
  167. if (a == true) {
  168. if (t == 1 && r != 11) {
  169. return "one"; // i.e. 1st, 21st, 101st, 121st ...
  170. } else if (t == 2 && r != 12) {
  171. return "two"; // i.e. 2nd, 22nd, 102nd, 122nd ...
  172. } else if (t == 3 && r != 13) {
  173. return "few"; // i.e. 3rd, 23rd, 103rd, 123rd ...
  174. } else {
  175. return "other"; // i.e. 4th, 11th, 12th, 24th ...
  176. }
  177. } else {
  178. if (e == 1 && l) {
  179. return "one"; // i.e. 1 day
  180. } else {
  181. return "other"; // i.e. 0 days, 2 days, 3 days
  182. }
  183. }
  184. ```
  185. If your language, like French, do not have complicated cardinal rules, you may
  186. use the French's version of it:
  187. ```javascript
  188. function (e, a) {
  189. return a ? 1 == e ? "one" : "other" : e >= 0 && e < 2 ? "one" : "other";
  190. }
  191. ```
  192. If your language, like Chinese, do not have any pluralization rule at all you
  193. may use the Chinese's version of it:
  194. ```javascript
  195. function (e, a) {
  196. return "other";
  197. }
  198. ```