Giter Club home page Giter Club logo

angular.i18n.properties's Introduction

angular.i18n.properties

lightweight angular module for providing internationalization to angular from ‘.properties’ files

it's a simple rewrite of https://github.com/jquery-i18n-properties/jquery-i18n-properties in angular style without use of JQuery

Usage

Using the module

  1. Include it on your <head> section after your angular.js files:
<script type="text/javascript" language="JavaScript"
  src="js/angular.i18n.properties.min.js"></script>
  1. Initialize the module, and access a translated value (assuming a key named ‘some.key‘ exists in the properties.Messages_en exists):
<script>
	var app = angular.module("myApp", ['angularI18nProperties']);
	
	app.controller('myCtrl', ['i18nProperties', function(i18nProperties) {
	  var mctrl = this;
	
	  // you better deport this into a service if you have more than one controller
    mctrl.changeLang(lang) {    
      i18nProperties.i18n.properties({
        name : 'Messages',
        language : lang,
        path : 'properties/',
        mode : 'map',
        cache : false,
        callback : function() {
          //some action you want after trad is complete
        }
      });
    };
    
    mctrl.changeLang('en'); // init by default to english
	}]);
	
</script>

then in your html page

<div ng-controller="myCtrl as mctrl" ng-cloak>
  <h3 class="panel-title">{{'my.title' | translate}}</h3>
  <button type="button" class='btn btn-default' ng-click="mctrl.changeLang('fr')">{{'french' | translate}}</button>
  <button type="button" class='btn btn-default' ng-click="mctrl.changeLang('en')">{{'english' | translate}}</button>
</div>

Building a minified JavaScript file

  1. Install the closure compiler tool:

    apt-get update && apt-get install closure-compiler

  2. Run it:

    closure-compiler --js angular.i18n.properties.js \ --js_output_file angular.i18n.properties.min.js

angular.i18n.properties's People

Contributors

laac avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.