Socket
Socket
Sign inDemoInstall

internationalization

Package Overview
Dependencies
3
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Protect your apps from supply chain attacks

Install

internationalization

i18n

    0.1.2latest
    GitHub
    npm

Version published
Maintainers
1
Weekly downloads
16
increased by220%

Weekly downloads

Readme

Source

internationalization

NPM Version Build Status

setup

i18n = require('internationalization');

app.use(i18n.middleware({
    directory: path.join(__dirname, 'locales'),
    fallback: "en",
    cookie: "lang" // default is "lang"
}));

directory layout

files under then same directory will be merged(file name does not matter)

locales
├── en
│   ├── foo.ini
│   └── bar.ini
└── zh
    └── index.ini

usage

span= _("Hello {username}", {username: username})
span= _("Hello {1}", username)
input(placeholder=_("Password") type="password")
Hello {username} = Guten Tag {username}
Hello {1} = Guten Tag {1}
Password = Passwort

namespace

span= _("profile:Hello {username}", {username: username})
[profile]
Hello {username} = Guten Tag {username}

client side

app.use(i18n.javascript({
    directory: path.join(__dirname, 'locales'),
}));

include in html

<script src="/i18n.js"></script>
<script>
console.log(i18n.resource);
console.log(i18n.lang);
</script>

more options:

  • cookie default lang
  • path default /i18n.js
  • exportAs default i18n

angularjs intergartion

app.use(i18n.angular({
    directory: path.join(__dirname, 'locales'),
    module: 'i18n',
    service: 'i18n',
    filter: 'translate'
}));

include in html

<script src="/path/to/angularjs.js"></script>
<script src="/i18n.js"></script>

using filter

<p>{{'delete warning'| translate:resource.name}}</p>
<button>{{'action:delete' | translate}}</button>

using service

app.directive("", function(i18n)->
    return {
        link: function(){
            console.log(i18n.translate("resource key", {name: "foo"}));
        }
    };

generate/update language files(TBD)

directory: 'locales'
views: 'views/**.jade'

grunt i18n will scan the view direcotry for _() and __()

$ grunt i18n de

Keywords

FAQs

Last updated on 22 Jun 2016

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc