ngx-translate
Template parser for Installation
Just yarn install ngx-translate-parser-plural-select
and use when
adding ngx-translate
to the imports
section in your @NgModule
:
Usage
Now you can use plural
and select
in your translations.
And even more complex usages:
Notes
Plural supports (first rule matching the value will be applied):
=value
— matches exact value (e.g.=0
,=1
)zero
,one
,two
... — matches values ending in 0, 1, 2, ... that are not between 10 and 19 (inclusive)few
— matches 2, 3, and 4many
— matches any value greater than 4 and any non-integer valueother
— matches any value
v1.1+
]
Custom pipes [If you want to define your own pipes to use as {variable, *pipe_name*, *pipe_options*}
, you can use a factory to
create the TranslateICUCustomParser
, the class taking a parameter consisting of a dictionary of custom pipes.
Example
... ;
This allows you to use the ?
pipe:
Hello, {name, ?, {{name}} : {stranger}}!
Pipe function parameters
The parameters given to the pipe function are:
- the value of the variable the pipe is being applied on
- an array of the strings between the options
- an array of the options,
where the application of the pipe is on a string of the format {value, pipe_name, parameter0 {option0} parameter1 {option1} ... parameterN {optionN} parameterN+1}
Concretely:
During the parsing of the string 'Hello, {name, myPipe, J {Johnny} K {Kenny} L {Lenny} M {Maurice}}'
,
the pipe defined in the dictionary passed to the TranslateICUParser
class constructor under the myPipe
key
will be called with parameters:
- the value of the
name
property of the object passed to thengx-translate
function/directive [' J ', ' K ', ' L ', ' M ', '']
['Johnny', 'Kenny', 'Lenny', 'Maurice']