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

ember-tml

v1.0.13

Published

The default blueprint for ember-cli addons.

Downloads

8

Readme

Ember TML

Build Status

NPM

This addon adds helpers for doing advanced localization of your ember apps with Translation Markup Language (TML) by Translation Exchange.

Translation Markup Language (TML) is a simple markup language that provides syntax for identifying dynamic data and decorations within strings. TML aims at abstracting out the decoration mechanisms of the string and instead provides its own simple, but powerful syntax. This allows for translation sharing across multiple applications and platforms.

Installation

ember install ember-tml

Configuration

The first thing you need to do to get started with Ember TML is sign up for a free Translation Exchange account and create your first project.

Once you have created a project and have your project key and token you must configure the service:

// config/environment.js
module.exports = function(environment) {
  var ENV = {
    tml: {
      key: "YOUR_PROJECT_KEY"
    }
  }
}

Usage

Initializing the SDK

To start using tml in your templates you will need to initialize the SDK. We suggest doing it in the beforeModel hook of your application route.

This will retrieve any translations from either your cache or the CDN before rendering any templates.

// app/routes/application.js
export default Ember.Route.extend({
  beforeModel(){
    return this.get('tml').initialize();
  }
});

Helpers

The Ember TML Addon provides a few helpers and a service:

{{tr}} Helper

tr is the basic translate function. It takes 3 parameters:

  • label is the only required parameter.
  • description is an optional parameter, but should always be used if the label by itself is not sufficient enough to provide the meaning of the phrase.
  • tokens is an optional parameter that contains a hash of token values to be substituted in the label.

This is what it should look like in your templates:

<div>{{tr "Hello World" }}</div>
<div>{{tr "Invite" "Link to invite your friends"}}</div>
<div>{{tr "Welcome {user}!" user=userName}}</div>
<div>{{tr "You have {count || message, messages}" count=1}}</div>
<div>{{tr "You have {count || message, messages}" count=5}}</div>

yields:

<div>Hello World</div>
<div>Invite</div>
<div>Welcome Jane!</div>
<div>You have 1 message</div>
<div>You have 5 messages</div>

{{trl}} Helper

trl works the same as tr but should be used for attribute values.

<img src="..." title={{trl "Hello World"}} />
{{input placeholder=(trl "Enter email address")}}

yields:

<img src="..." title="Hello World" />
<input placeholder="Enter email address" />

You can find more on how to use TML in the docs at Translation Exchange

API

TML Service Api

The TML service will be injected into Controllers, Routes, Views and Components.

Ember.get(this, 'tml').trl("Hello World");

and includes some handy methods for working with TML:

currentTranslator
an object representing the current logged in translator

Ember.get(this, 'tml.currentTranslator');
// {
//   name: "translator_username",
//   inline: true
// }

currentSource
a string of the current source

Ember.get(this, 'tml.currentSource');
// "index"

currentApplication
return an object representing your Translation Exchange application

Ember.get(this, 'tml.currentApplication');
// {
//   id: 123,
//   key: "APP_KEY",
//   name: "Dom Examples",
//   current_locale: "zh",
//   default_locale: "en-US",
//   features: {...},
//   languages: [...]
// }

currentLanguage
returns the currently selected language

Ember.get(this, 'tml.currentLanguage');
// {
//   id: 233,
//   english_name: "Russian",
//   native_name: "Русский",
//   locale: "ru",
//   right_to_left: false,
//   flag_url: "https://s3-us-west-1.amazonaws.com/trex-snapshots/flags/default/languages/16/ru.png"
// }

availableLanguages
returns a list of all available languages for your project

translationModeEnabled
returns whether or not the application is currently in translation mode

translate(label [,description, tokens])
tr(label [,description, tokens])
works the same as the tr helper

translateLabel(label [,description, tokens])
trl(label [,description, tokens])
works the same as the trl helper

changeLanguage(locale)
sets the current language

Building a Language Selector

<ul>
  {{#each tml.availableLanguages as |language|}}
    <li>
      <a {{action (action tml.changeLanguage) language.locale}}>
        <img src={{language.flag_url}} />
        {{tr language.english_name}}
      </a>
    </li>
  {{/each}}
</ul>

Links

  • Register on TranslationExchange.com: http://translationexchange.com

  • Follow TranslationExchange on Twitter: https://twitter.com/translationx

  • Connect with TranslationExchange on Facebook: https://www.facebook.com/translationexchange

  • If you have any questions or suggestions, contact us: [email protected]

Copyright and license

Copyright (c) 2017 Translation Exchange, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.