npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-dynamic-locale

v0.1.38

Published

A minimal module that adds the ability to dynamically change the locale

Downloads

137,515

Readme

Angular Dynamic Locale

Requirements

  • AngularJS v1.0.7+ is currently required.

Changing the locale

This module defines two services, these are tmhDynamicLocale and tmhDynamicLocaleCache.

The service tmhDynamicLocale provides has one method set(newLocale) to change the locale.

tmhDynamicLocale.set('it');

Keep in mind that the locale will be changed asynchronously

After the locale is changed, the event '$localeChangeSuccess' will be triggered.

Calling tmhDynamicLocale.set will return a promise that will be resolved when the locale is loaded and will resolve to the new locale.

The service tmhDynamicLocaleCache is a $cache of all the loaded locales, where the key is the locale id and the value is the locale object.

This module expects for the angular locales to be present at angular/i18n/angular-locale_{{locale}}.js. If the locales are at another URL, this can be changed at tmhDynamicLocaleProvider using localeLocationPattern(string).

It is possible to specify a storage location for the locale using tmhDynamicLocaleProvider.useStorage(storageName), the name of the storage must follow the same signature as $cookieStore. The default storage location is to use a $cache, this default storage is not persistent.

It is possible to ask the storage to be $cookieStore using the shortcut tmhDynamicLocaleProvider.useCookieStorage(), internally this is exactly as performing tmhDynamicLocaleProvider.useStorage('$cookieStore')

Also it is possible to set a default language using tmhDynamicLocaleProvider.defaultLocale(locale).

Installation

Using npm:

npm install angular-dynamic-locale

Using bower:

bower install angular-dynamic-locale

Usage

Add the js file to your html:

<script src="myPath/tmhDynamicLocale.js"></script>

Add the module to your dependencies:

angular.module('myApp', ['tmh.dynamicLocale', ...])

Inject tmhDynamicLocale to your controller and set the desired locale:

angular.module('myApp').controller('myController', [..., 'tmhDynamicLocale',
  function(..., tmhDynamicLocale) {
    tmhDynamicLocale.set('en');
  }
])

Also, here's an example of how you may optionally override the default path (angular/i18n/angular-locale_{{locale}}.js) to the stored Angular i18n locale files in your project:

angular.module('myApp', ['tmh.dynamicLocale'])
  .config(function(tmhDynamicLocaleProvider) {
    tmhDynamicLocaleProvider.localeLocationPattern('/base/node_modules/angular-i18n/angular-locale_{{locale}}.js');
  });

Lastly, if you need to set a default locale, you can do it like this:

angular.module('myApp', ['tmh.dynamicLocale'])
  .config(function(tmhDynamicLocaleProvider) {
    tmhDynamicLocaleProvider.defaultLocale('en');
  });

Development

Requirements

  1. Install Node.js and NPM (should come with)

  2. Install global dependencies grunt-cli and bower:

    $ npm install -g grunt-cli bower
  3. Install local dependencies:

    $ npm install

Running the tests

$ grunt karma:unit

to run the test once

or

$ grunt karma:autotest

to run the tests continuously