Initial commit
[yaffs-website] / node_modules / y18n / README.md
1 # y18n
2
3 [![Build Status][travis-image]][travis-url]
4 [![Coverage Status][coveralls-image]][coveralls-url]
5 [![NPM version][npm-image]][npm-url]
6 [![js-standard-style][standard-image]][standard-url]
7
8 The bare-bones internationalization library used by yargs.
9
10 Inspired by [i18n](https://www.npmjs.com/package/i18n).
11
12 ## Examples
13
14 _simple string translation:_
15
16 ```js
17 var __ = require('y18n').__
18
19 console.log(__('my awesome string %s', 'foo'))
20 ```
21
22 output:
23
24 `my awesome string foo`
25
26 _pluralization support:_
27
28 ```js
29 var __n = require('y18n').__n
30
31 console.log(__n('one fish %s', '%d fishes %s', 2, 'foo'))
32 ```
33
34 output:
35
36 `2 fishes foo`
37
38 ## JSON Language Files
39
40 The JSON language files should be stored in a `./locales` folder.
41 File names correspond to locales, e.g., `en.json`, `pirate.json`.
42
43 When strings are observed for the first time they will be
44 added to the JSON file corresponding to the current locale.
45
46 ## Methods
47
48 ### require('y18n')(config)
49
50 Create an instance of y18n with the config provided, options include:
51
52 * `directory`: the locale directory, default `./locales`.
53 * `updateFiles`: should newly observed strings be updated in file, default `true`.
54 * `locale`: what locale should be used.
55 * `fallbackToLanguage`: should fallback to a language-only file (e.g. `en.json`)
56   be allowed if a file matching the locale does not exist (e.g. `en_US.json`),
57   default `true`.
58
59 ### y18n.\_\_(str, arg, arg, arg)
60
61 Print a localized string, `%s` will be replaced with `arg`s.
62
63 ### y18n.\_\_n(singularString, pluralString, count, arg, arg, arg)
64
65 Print a localized string with appropriate pluralization. If `%d` is provided
66 in the string, the `count` will replace this placeholder.
67
68 ### y18n.setLocale(str)
69
70 Set the current locale being used.
71
72 ### y18n.getLocale()
73
74 What locale is currently being used?
75
76 ### y18n.updateLocale(obj)
77
78 Update the current locale with the key value pairs in `obj`.
79
80 ## License
81
82 ISC
83
84 [travis-url]: https://travis-ci.org/yargs/y18n
85 [travis-image]: https://img.shields.io/travis/yargs/y18n.svg
86 [coveralls-url]: https://coveralls.io/github/yargs/y18n
87 [coveralls-image]: https://img.shields.io/coveralls/yargs/y18n.svg
88 [npm-url]: https://npmjs.org/package/y18n
89 [npm-image]: https://img.shields.io/npm/v/y18n.svg
90 [standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
91 [standard-url]: https://github.com/feross/standard