You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
writtenNumber(1234, {lang:'vi'}); // => 'một ngàn hai trăm và ba mươi bốn'
65
-
```
66
-
67
-
## Configure your own language
68
-
Each language has it's own unique grammar exceptions. You can create your own language.json file in the folder "i18n" and give writtenNumber support for it. I don't think the current scheme and logic cover all the cases, but may be cover some.
69
-
70
-
##### useLongScale:
71
-
'Boolean' that indicates if it use [long or short scale](http://en.wikipedia.org/wiki/Long_and_short_scales). This differs the meaning of the words `billion`, `trillion` and so on.
72
-
73
-
##### baseSeparator:
74
-
'String' that separates the base cardinal numbers.
75
-
Example: 29 -> twenty`-`eight. Spanish uses the conector " y ".
76
-
77
-
##### unitSeparator:
78
-
'String' that separates the units from the last base cardinal numbers.
79
-
Example: 1234 -> one thousand two hundred **and** thirty-four
80
-
81
-
##### allSeparator:
82
-
'String' that separates all cardinals, not only the last one.
83
-
Example: 1125 -> ألف **و**مائة **و**خمسة **و**عشرون
84
-
85
-
##### base:
86
-
Base cardinals numbers. Numbers that have unique names and are used to build others.
87
-
88
-
##### units:
89
-
Number units.
90
-
It can be:
91
-
- String
92
-
- Object normal flow. Give support to singular, dual, and plural units. English does not need this, but spanish does.
93
-
```json
94
-
{
95
-
"singular": "millón",
96
-
"plural": "millones"
97
-
}
98
-
```
99
-
- Object with `useBaseInstead` exception.
100
-
In some languages like spanish and arabic, specific units like "ciento", use the base cardinal number instead.
101
-
- Object with `useBaseException`: You can also specify with which unit (1 to 9) you don't
102
-
want use the base cardinal instead and use the regular behaviour:
103
-
```json
104
-
{
105
-
"singular": "ciento",
106
-
"useBaseInstead": true,
107
-
"useBaseException": [1]
108
-
}
109
-
```
110
-
- Object with `avoidPrefixException` exception:
111
-
In some languages like spanish, specific units like "mil" does not use the base
112
-
cardinal number prefix for unit 1.
113
-
```json
114
-
{
115
-
"singular": "mil",
116
-
"avoidPrefixException": [1]
117
-
}
118
-
```
119
-
- Object with `avoidInNumberPlural` exception.
120
-
In some languages like french, specific units like "cent" does not use the plural form inside of
121
-
numbers wioth trailing numbers other than 0, for example "deux cents" and "deux cent trois".
122
-
```json
123
-
{
124
-
"singular": "cent",
125
-
"plural": "cents",
126
-
"avoidInNumberPlural": true
127
-
}
128
-
```
129
-
- Object with `restrictedPlural` boolean:
130
-
If plural is used only for numbers from 3 to 10 , but the singular form is used if the number is older than 11.
131
-
132
-
##### unitExceptions:
133
-
Sometimes grammar exceptions affect the base cardinal joined to the unit. You
134
-
can set specific exceptions to any base cardinal number.
135
-
Spanish example:
136
-
```
137
-
Without Exception (Wrong): 1232000 -> **uno** millón doscientos treinta y dos mil
138
-
With Exception: 1232000 -> **un** millón doscientos treinta y dos mil
139
-
```
140
-
141
67
## Contributing
68
+
69
+
### Configure your own language
70
+
Each language has its own unique grammar exceptions. You can create your own
71
+
language.json file in the folder "i18n" and give writtenNumber support for it. I
72
+
don't think the current scheme and logic cover all the cases, but may be cover
73
+
some.
74
+
75
+
The following parameters have been used for the currently available languages:
|`useLongScale`| boolean | Indicates if it uses [long or short scale](http://en.wikipedia.org/wiki/Long_and_short_scales). | This differs the meaning of the words `billion`, `trillion` and so on. |
83
+
|`baseSeparator`| string | Separates the base cardinal numbers. | 29 -> twenty`-`eight. Spanish uses the connector " y " |
84
+
|`unitSeparator`| string | Separates the units from the last base cardinal numbers. | 1234 -> one thousand two hundred **and** thirty-four |
85
+
|`allSeparator`| string | Separates all cardinals, not only the last one. | 1125 -> ألف **و**مائة **و**خمسة **و**عشرون |
86
+
|`base`| Object | Base cardinals numbers. Numbers that have unique names and are used to build others. ||
87
+
|`alternativeBase`| Object | Alternative versions of base cardinals numbers for usage with specific units. These bases will be treated as an extension for the default `base`. |``` "alternativeBase": { "feminine": {"1":"одна","2":"дві"} } ```|
88
+
|`units`| Array | A list of number units (string or Object). Gives support to singular, dual an plural units. Check the Object parameters below. ||
89
+
|`unitExceptions`| Object | Sometimes grammar exceptions affect the base cardinal joined to the unit. You can set specific exceptions to any base cardinal number. | Converting 1232000 in Spanish: Without Exception (Wrong): -> **uno** millón doscientos treinta y dos mil With Exception: -> **un** millón doscientos treinta y dos mil |
90
+
91
+
### Units parameters
92
+
93
+
A `unit` can be:
94
+
- A simple string. e.g. `"hundred"`
95
+
- An Object with multiple parameters:
96
+
97
+
| Unit parameter | Description | e.g. of languages |
|`useBaseInstead`| Use the base cardinal number instead. |`es`,`hu`,`pt`|
105
+
|`useBaseException`| Specify with which unit (1 to 9) you don't want to use the base, and instead use the regular behavior. |`es`,`hu`,`pt`|
106
+
|`avoidPrefixException`| Units not using the base cardinal number prefix for unit 1. |`id`,`tr`,`it`|
107
+
|`avoidInNumberPlural`| Units not using the plural form with trailing numbers other than 0. |`fr`|
108
+
|`restrictedPlural`| Plural only for 3 to 10. Singular if >= 11. |`ar`|
109
+
|`useSingularEnding`| Use singular form for numbers ending with 1. |`uk`|
110
+
|`useFewEnding`| Use _few_ form for numbers ending with 2, 3 or 4. |`uk`|
111
+
|`avoidEndingRules`| Plural form used instead of `useSingularEnding` and `useFewEnding`|`uk`|
112
+
113
+
114
+
115
+
### Versioning
142
116
Do your changes and submit a PR. If you've write access and want to bump the version, run `mversion [major|minor|patch] -m`. That'll bump both `bower.json` and `package.json`.
0 commit comments