Socket
Book a DemoInstallSign in
Socket

ngx-translate-parser-plural-select

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-translate-parser-plural-select

ngx-translate parser that supports pluralization and select (a la Angular's i18n module)

Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
1.4K
-4.93%
Maintainers
1
Weekly downloads
 
Created
Source

Template parser for ngx-translate

Installation

Just yarn install ngx-translate-parser-plural-select and use when adding ngx-translate to the imports section in your @NgModule:

@NgModule({
    ...
    imports: [
    	...
        TranslateModule.forRoot({
            parser: {
            	provide: TranslateParser,
            	useClass: TranslateICUParser
            }
        })
    ]
})

Usage

Now you can use plural and select in your translations.

{
    "HERO": "The hero is {gender, select, m {male} f {female}}",
    "WOLVES": "The hero saw {wolves, plural, =0 {no wolf} =1 {a wolf} =2 {two wolves} other {a pack of wolves}}",
    "CROWS": "You could see {crows.length, plural, =1 {a crow} few {a few crows} many {a murder of crows}}"
}

And even more complex usages:

{
    "COMPLEX": "{count, plural, =0 { nadie } =1 {{gender, select, m {un hombre} f {una mujer}}} other {{{heroes.length}} {gender, select, m {hombres} f {mujeres}}}}"
}

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 4
  • many — matches any value greater than 4 and any non-integer value
  • other — matches any value

Keywords

ngx-translate

FAQs

Package last updated on 17 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts