Skip to content

Commit 915650d

Browse files
authoredFeb 22, 2023
lower required nim version and update readme (#3)
1 parent cd9e363 commit 915650d

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed
 

‎README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ type
3131
3232
i18nInit Locale, true:
3333
hello:
34+
# translations can be string literal
3435
English = "Hello, $name!"
3536
Chinese = "你好, $name!"
3637
ihaveCat:
3738
English = "I've cats"
3839
Chinese = "我有猫"
40+
# translation definition can have sub-translation definition
3941
withCount:
42+
# translations can be lambda / closure
4043
English = proc(count: int): string =
4144
case count
4245
of 0: "I don't have a cat"
@@ -64,6 +67,9 @@ echo ihaveCat(Chinese)
6467
# prints 我有五只猫
6568
echo ihaveCat_withCount(Chinese, 5)
6669
70+
# or like this ( because Nim compiler is smart! )
71+
echo ihaveCatWithCount(Chinese, 5)
72+
6773
# compiler error here since each function is generated with the same signature from lambda
6874
echo ihaveCat_withCount(Chinese, "some str")
6975
```
@@ -106,12 +112,6 @@ proc hello*(locale: Locale, args: varargs[string, `$`]): string =
106112

107113
So, we have just locale runtime check, but since that's enum, we're still going fast!
108114

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-
115115
## Contributions
116116

117117
Contributions, Ideas are welcome! For now, there're just simple test cases.

‎ni18n.nimble

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ license = "MIT"
55
srcDir = "src"
66
installExt = @["nim"]
77

8-
requires "nim >= 1.6.10"
8+
requires "nim >= 1.0.0"
99

1010
import strutils, os
1111

‎src/ni18n.nim

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ runnableExamples:
4646
# prints 我有五只猫
4747
echo ihaveCat_withCount(Chinese, 5)
4848

49+
# or like this ( because Nim compiler is smart! )
50+
echo ihaveCatWithCount(Chinese, 5)
51+
4952
## **Notes For `ni18n` DSL**
5053
##
5154
## DSL has top-level translation definitions and sub-translation definitions.

‎tests/test_simple.nim

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ suite "simple test suite":
3939
check hello(Chinese, "name", "黄小姐") == "你好, 黄小姐!"
4040

4141
test "simple test #2":
42-
check ihaveCat_withCount(Chinese, 0) == "我没有猫"
43-
check ihaveCat_withCount(Chinese, 1) == "我有一只猫"
44-
check ihaveCat_withCount(Chinese, 5) == "我有五只猫"
42+
check ihaveCatWithCount(Chinese, 0) == "我没有猫"
43+
check ihaveCatWithCount(Chinese, 1) == "我有一只猫"
44+
check ihaveCatWithCount(Chinese, 5) == "我有五只猫"
4545

4646
test "simple test #3":
4747
check ihaveCat(English) == "I've cats"

0 commit comments

Comments
 (0)