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-applanga

v1.2.2

Published

<p align="center"> <a href="https://applanga.com"> <img height="120" src="https://applanga.com/web/images/applanga_facebook.png"> </a> <a href="https://hellofresh.com"> <img height="120" src="https://www.hellofresh.de/images/hellofresh/press

Downloads

42

Readme

Angular Applanga

Codeship Status for hellofresh/angular-applanga

Client that talks to a proxied version of the Applanga API. Also includes a tool to import your data into Applanga.

How to install

Simply install it with Bower or NPM:

$ bower install angular-applanga
$ npm install angular-applanga

Make sure you have the angular sanitize library also included in your libs!

How to configure

To include in your app add the following module: Applanga.

angular.module('testApp', ['Applanga']);

To set the Applanga languages or groups use the ApplangaProvider in your app's config.

angular.module('testApp').config(function(ApplangaProvider) {
  ApplangaProvider.setLanguages(['nl-NL', 'nl-BE', 'nl']) // Set all languages to fetch from Applanga
    .setGroups(['main']) // Set all groups to fetch from Applanga
    .setTranslateLanguage('nl-NL') // Set the default language used for translating
    .setTranslateGroups(['main']) // Set the default groups used for translating
    .setUrl('http://www.hellofresh.com/api/applanga');
});

The default values for these settings are for languages: ['en'] and for groups: ['main'].

How to use

The main usage of the app will be the directives inside the module. There are two directives: applanga and applanga-safe, the first is for normal translating and the second one will sanitize the input too.

applanga directive

To translate a textNode you could use the applanga directive like this:

<div applanga="applanga-id" language="en" groups="main|other">
  Testing out the new applanga directive, on {{date}}.
</div>

As you can see the element already contains a textNode, this is the failsafe, before the app has loaded your Applanga translations.

The value of the translation in Applanga could be: "Testing out the new applanga directive, on {{date}}." the applanga directive would $interpolate the {{date}} value to the value on the parent scope.

applanga-safe directive

To translate the HTML content of an element you could use the applanga-safe directive like this:

<div applanga-safe="applanga-id" language="en" groups="main|other">
  <p>
    Testing out the new applanga-safe directive, on {{date}}.
  </p>
</div>

Again the failsafe value of this node is in the element. The translation in Applanga would be:

<p>
  Testing out the new applanga-safe directive, on {{date}}.
</p>

Everything in this directive works the same as the normal applanga directive, but the value is being sanitized, so things like <script></script> will be removed from the input string.

aplanga filter

The package also includes a filter that will translate the provided text for you. So for example:

<p ng-bind="'test-this-filter' | applanga"></p>

The downside of the filter is, is that it won't be able to $interpolate the value for you, so we recommend to use the directives instead.

You can also define groups and language for the filter, like so:

<p ng-bind="'test-this-filter' | applanga:'en':['main', 'other']"></p>

Applanga service

This service is being derived from the ApplangaProvider, this is where most of the magic happens.

The Applanga service has four methods:

  • ::setTranslateLanguage(language) change the default language used by the ApplangaProvider. By default this is the first element in the array.
  • ::setTranslateGroups(groups) change the default group used by the ApplangaProvider. By default this is the first element in the array.
  • ::fetch will fetch new data from the API. This happens automatically when you change something from the applangaConfig object inside this service.
  • ::translate(key, language = null, groups = null) will translate the key for you. If you don't provide it with a language or group it will take the default language or group.
  • ::isResolved this will return a promise, that will be resolved once the translations are loaded.
  • ... also all the methods defined in for the ApplangaProvider are available on this object, so if you want to change the main languages, just call the ::setLanguages function

ApplangaInterpolate service

If you want to take matters in your own hands you can call the ApplangaInterpolate service directly and interpolate your translation with a given scope. To call it:

ApplangaInterpolate.parse('{{key}}', {
  key: 'test'
}); // test

ApplangaSanitizedInterpolate service

You could also sanitize the input, before you interpolate, this you could do with the ApplangaSanitizedInterpolate service. To use it:

ApplangaSanitizedInterpolate.parse('<script>maliciousJS</script><p>{{key}}</p>', {
  key: 'test'
}); // <p>test</p>