All Projects → i18next → Ng I18next

i18next / Ng I18next

Licence: mit
translation for AngularJS using i18next

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Ng I18next

Musicplayer
A minimal music player built on electron.
Stars: ✭ 145 (-9.94%)
Mutual labels:  angularjs
Mean Blog
Blog using Nodejs, Expressjs, Angularjs and Mongodb. MEAN Javascript Fullstack application
Stars: ✭ 151 (-6.21%)
Mutual labels:  angularjs
Angular Promise Buttons
Chilled loading buttons for AngularJS
Stars: ✭ 156 (-3.11%)
Mutual labels:  angularjs
Blur Admin
AngularJS Bootstrap Admin Panel Framework
Stars: ✭ 11,274 (+6902.48%)
Mutual labels:  angularjs
Poddr
Podcatcher made with Electron and Angular
Stars: ✭ 149 (-7.45%)
Mutual labels:  angularjs
Dunglasangularcsrfbundle
Automatic CSRF protection for JavaScript apps using a Symfony API
Stars: ✭ 152 (-5.59%)
Mutual labels:  angularjs
Highcharts Ng
AngularJS directive for Highcharts
Stars: ✭ 1,741 (+981.37%)
Mutual labels:  angularjs
Valdr
A model centric approach to AngularJS form validation
Stars: ✭ 158 (-1.86%)
Mutual labels:  angularjs
Angularjs Typescript Webpack
AngularJS 1.7, typescript 3 and webpack 4 starter project based on angular tutorial
Stars: ✭ 150 (-6.83%)
Mutual labels:  angularjs
Serviceportal Widget Library
A collection of Service Portal custom widgets
Stars: ✭ 155 (-3.73%)
Mutual labels:  angularjs
Angular Tree Dnd
Display tree table (or list) & event Drap & Drop (allow drag multi tree-table include all type: table, ol, ul) by AngularJS
Stars: ✭ 146 (-9.32%)
Mutual labels:  angularjs
Lowpolify
Create low-poly art from any image 🌟🌟
Stars: ✭ 149 (-7.45%)
Mutual labels:  angularjs
Pagermon
Multimon-ng pager message parser and viewer
Stars: ✭ 154 (-4.35%)
Mutual labels:  angularjs
Translatr
💬 Translate to multiple languages at once
Stars: ✭ 145 (-9.94%)
Mutual labels:  angularjs
Ng Currency
Currency with AngularJS made easy!
Stars: ✭ 156 (-3.11%)
Mutual labels:  angularjs
Siberian
Siberian Single App Edition (SAE), free and open-source app builder.
Stars: ✭ 144 (-10.56%)
Mutual labels:  angularjs
Ngmeta
Dynamic meta tags in your AngularJS single page application
Stars: ✭ 152 (-5.59%)
Mutual labels:  angularjs
Ionic Toast
'ionic-toast' bower component for ionic framework applications
Stars: ✭ 160 (-0.62%)
Mutual labels:  angularjs
Angular Ui Tour
Product tour using Angular UI Bootstrap Tooltips
Stars: ✭ 157 (-2.48%)
Mutual labels:  angularjs
Angular Bootstrap Checkbox
A checkbox for AngularJS styled to fit the Twitter Bootstrap standard design
Stars: ✭ 154 (-4.35%)
Mutual labels:  angularjs

ng-i18next - use i18next with AngularJS Build Status

Project goal is to provide an easy way to use i18next with AngularJS 1.x:

  • ng-i18next directive
  • i18next filter

First check out the documentation by Jan Mühlemann.

Features

  • AngularJS provider, directive and filter
  • variable binding (translates again when variable changes)
  • nested translations ($t('hello'); see i18next documentation)
  • scope variables in translations (if the translation contains directives of variables like {{hello}}, they'll get compiled)
  • sprintf support (directive and provider)

Installation Bower

You can install ng-i18next as a bower dependency:

bower install ng-i18next

Installation npm

You can install ng-i18next as a npm dependency:

npm install ng-i18next

Upgrading from <=0.5.5

You will need to

  1. Move initialization of i18next from the ng-i18next provider within Angular to i18next natively before booting Angular
  2. Change translations using the $i18next provider in you Angular code. From $i18next('localeKey') to $i18next.t('localeKey')

Usage

First add

to your HTML file. AngularJS, ngSanitize, i18next, and i18next-xhr-backend have to be loaded before ng-i18next!

Before booting angular use i18next configuration system to configure and load your localization resources. Refer to i18next configuration reference.

window.i18next
	.use(window.i18nextXHRBackend);

window.i18next.init({
	debug: true,
	lng: 'de', // If not given, i18n will detect the browser language.
	fallbackLng: 'dev', // Default is dev
	backend: {
		loadPath: '../locales/{{lng}}/{{ns}}.json'
	},
	useCookie: false,
	useLocalStorage: false
}, function (err, t) {
	console.log('resources loaded');
});

There are three ways to use ng-i18next:

filter

<p>{{'hello' | i18next}}</p>

=> translates hello

<p>{{hello | i18next}}</p>

=> translates $scope.hello

directive

Basics

<p ng-i18next="hello"></p>

=> translates hello

<p ng-i18next="{{hello}}"></p>

=> translates $scope.hello

<p ng-i18next>hello</p>

=> translates hello (uses the content of the p-tag)

<p ng-i18next>{{hello}}</p>

=> translates $scope.hello (uses the content of the p-tag)

Note, that HTML isn't compiled!

HTML

<p ng-i18next="[html]hello"></p>

=> translates hello and compiles HTML

<p ng-i18next="[html]{{hello}}"></p>

=> translates $scope.hello and compiles HTML

Attributes

<a href="#" ng-i18next="[title]hello">This is a link.</a>

=> translates hello and sets it as the title

<a href="#" ng-i18next="[title]{{hello}}">This is a link.</a>

=> translates $scope.hello and sets it as the title

You can combine both, too!

Attributes + text content

<a href="#" ng-i18next="[title]hello;content"></a>

=> translates hello and sets it as the title => translates content and sets it as the text of the link.

<a href="#" ng-i18next="[title]{{hello}};{{content}}"></a>

=> translates $scope.hello and sets it as the title => translates $scope.content and sets it as the text of the link.

Attributes + HTML content

<a href="#" ng-i18next="[title]hello;[html]content"></a>

=> translates hello and sets it as the title => translates content and compiles the HTML as the content of the link.

<a href="#" ng-i18next="[title]{{hello}};[html]{{content}}"></a>

=> translates $scope.hello and sets it as the title => translates $scope.content and compiles the HTML as the content of the link.

Passing Options

You can also pass options:

<p ng-i18next="[i18next]({lng:'de'})hello"></p>

=> translates hello in German (de)

Passing Options + HTML

Also options work perfectly together with html:

<p ng-i18next="[html:i18next]({lng:'de'})hello"></p>

=> translates hello in German (de) and compiles it to HTML code.

Passing Options - sprintf

You can use i18next sprintf feature:

<p ng-i18next="[i18next]({sprintf:['a','b','c','d']})sprintfString">

where sprintfString could be The first 4 letters of the english alphabet are: %s, %s, %s and %s in your translation file.

Using the directive, postProcess:'sprintf' isn't neccassary. The directive will add it automatically when using sprintf in the options.

provider

=> translates hello

angular
	.module('MyApp', ['jm.i18next'])
	.controller('MyProviderCtrl', function ($scope, $i18next) {
		'use strict';
		$scope.hello = $i18next.t('hello');
});

=> translates hello with translate options

$scope.sprintf = $i18next.t('both.sprintf', { postProcess: 'sprintf', sprintf: ['a', 'b', 'c', 'd'] });

=> translates copyright label and use interpolation to add the year

locale

{
    "copyrightLabel": "Copyright __year__ Acme, Inc. All rights reserved",
}

JavaScript

$i18next.t('copyrightLabel', { year: this.$window.moment().year() });

Results

Copyright 2016 Acme, Inc. All rights reserved


For more, see examples.

There are two ways to run the examples:

gulp serve

Run this inside your ng-i18next directory. (This requires you to have NodeJS and gulp to be installed.)


Contribute

To contribute, you must have:

installed.

Load all dependencies using npm, bower and typings:

npm install
bower install
typings install

Build ng-i18next.js using Gulp:

gulp build

Test ng-i18next.js using Gulp:

gulp test

Examples

You can run the examples using:

gulp serve

(note that you have to be in the root directory of this project)

Do not just open the HTML files. That won't work.


Supported browsers

ng-i18next is tested with these browsers:

  • latest Firefox
  • latest Chrome
  • IE9 and above

IE8 isn't supported. ng-i18next should work with every browser that is supported by AngularJS.

However, last time we checked, just adding polyfills do the job on IE8.


Changelog

For changelog file please see CHANGELOG.md


License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].