|
31 | 31 |
|
32 | 32 | i18nInit Locale, true:
|
33 | 33 | hello:
|
| 34 | + # translations can be string literal |
34 | 35 | English = "Hello, $name!"
|
35 | 36 | Chinese = "你好, $name!"
|
36 | 37 | ihaveCat:
|
37 | 38 | English = "I've cats"
|
38 | 39 | Chinese = "我有猫"
|
| 40 | + # translation definition can have sub-translation definition |
39 | 41 | withCount:
|
| 42 | + # translations can be lambda / closure |
40 | 43 | English = proc(count: int): string =
|
41 | 44 | case count
|
42 | 45 | of 0: "I don't have a cat"
|
@@ -64,6 +67,9 @@ echo ihaveCat(Chinese)
|
64 | 67 | # prints 我有五只猫
|
65 | 68 | echo ihaveCat_withCount(Chinese, 5)
|
66 | 69 |
|
| 70 | +# or like this ( because Nim compiler is smart! ) |
| 71 | +echo ihaveCatWithCount(Chinese, 5) |
| 72 | +
|
67 | 73 | # compiler error here since each function is generated with the same signature from lambda
|
68 | 74 | echo ihaveCat_withCount(Chinese, "some str")
|
69 | 75 | ```
|
@@ -106,12 +112,6 @@ proc hello*(locale: Locale, args: varargs[string, `$`]): string =
|
106 | 112 |
|
107 | 113 | So, we have just locale runtime check, but since that's enum, we're still going fast!
|
108 | 114 |
|
109 |
| -## Todos |
110 |
| - |
111 |
| -- [ ] more readable ( `hello(Chinese, "name", "黄小姐")` -> `hello(Chinese, "黄小姐")` ) |
112 |
| -- [ ] cleaner lookup function ( `ihaveCat_withCount` -> `ihaveCat.withCount` ) |
113 |
| -- [ ] check the lowest nim version we can use ( current: `1.6.10` ) |
114 |
| - |
115 | 115 | ## Contributions
|
116 | 116 |
|
117 | 117 | Contributions, Ideas are welcome! For now, there're just simple test cases.
|
|
0 commit comments