Installations
npm install y18n-browser
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
7.9.0
NPM Version
4.2.0
Score
70.9
Supply Chain
99.3
Quality
75.2
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
nemophrost
Download Statistics
Total Downloads
1,364
Last Day
3
Last Week
4
Last Month
15
Last Year
72
GitHub Statistics
1 Stars
64 Commits
2 Watching
6 Branches
1 Contributors
Bundle Size
6.42 kB
Minified
2.29 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.0.2
Package Id
y18n-browser@1.0.2
Size
4.90 kB
NPM Version
4.2.0
Node Version
7.9.0
Total Downloads
Cumulative downloads
Total Downloads
1,364
Last day
-25%
3
Compared to previous day
Last week
-42.9%
4
Compared to previous week
Last month
400%
15
Compared to previous month
Last year
-50.3%
72
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
y18n-browser
The bare-bones internationalization library.
Examples
simple string translation:
1var __ = require('y18n').__ 2 3console.log(__('my awesome string %s', 'foo'))
output:
my awesome string foo
pluralization support:
1var __n = require('y18n').__n 2 3console.log(__n('one fish %s', '%d fishes %s', 2, 'foo'))
output:
2 fishes foo
JSON Language Files
The JSON language files can be stored anywhere as long as you can include them
when you instantiate a new Y18N.
File names correspond to locales, e.g., en.json
, pirate.json
.
When strings are observed for the first time they will be added to the JSON file corresponding to the current locale.
Usage
It is recommended to create a helper file/module to handle constructing a new Y18N instance like so:
y18n.js
1import Y18N from 'y18n-browser' 2 3export default new Y18N({ 4 sources: { 5 en: require('./path/to/en.json'), 6 pirate: require('./path/to/pirate.json'), 7 } 8})
Create an instance of y18n with the config provided, options include:
sources
: an object mapping to existing json source fileswriteLocalUpdates
: should newly observed strings be written to local storage, defaultfalse
.locale
: what locale should be used.fallbackToLanguage
: should fallback to a language-only file (e.g.en.json
) be allowed if a file matching the locale does not exist (e.g.en_US.json
), defaulttrue
.
Methods
import y18n from './my/instance/y18n'
Now you can use your configured instance anywhere.
y18n.__(str, arg, arg, arg)
Print a localized string, %s
will be replaced with arg
s.
y18n.__n(singularString, pluralString, count, arg, arg, arg)
Print a localized string with appropriate pluralization. If %d
is provided
in the string, the count
will replace this placeholder.
y18n.setLocale(str)
Set the current locale being used.
y18n.getLocale()
What locale is currently being used?
y18n.updateLocale(obj)
Update the current locale with the key value pairs in obj
.
Example locale json file
1{ 2 "Hello": "Hello!", 3 "Hello %s %s": "Hello %s %s", 4 "%d cat": { 5 "one": "%d cat", 6 "other": "%d cats" 7 }, 8 "%d %s cat": { 9 "one": "%d %s cat", 10 "other": "%d %s cats" 11 }, 12 "There is one monkey in the %s": { 13 "one": "There is one monkey in the %s", 14 "other": "There are %d monkeys in the %s" 15 } 16}
License
ISC
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: ISC License: LICENSE:0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More