Coder Social home page Coder Social logo

localize's Introduction

#Localize.js

Localize.js is a lightweight client-side library meant to enable easy localization in client-side web applications. Localization dictionaries can be sourced from an API or a local file. Supports All modern browsers and IE8+

##Usage

Minimal setup and initialization follows the following pattern:

// Create a new instance of the Localize class
var Localization = new Localize();

// Run initial setup to do basic configuration
Localization.setupLocalize({
  basePath: '/path/to/endpoint',
  currentLocale: 'en-US',
  defaultContext: 'UI-COMMON'
});

// Grab some content
Localization.getLocalizedData({
  context: 'UI-COMMON',
  pathSuffix: 'common.json'
});

At this point, the Localize class will be set up and ready for you to fetch localized text. This is usable in your Javascript code and your HTML. Also included is a handlebars helper for Ember applications.

###Text replacement in javascript Getting localized text in your javascript is performed by calling the fetch() method on the class and supplying it with a key.

Localization.fetch('someKey');

Text replacement in HTML

To localize text in your HTML, you can use any arbitrary element (<span> tags are recommended) with a class name of localize-me. This element will also need a data-key attribute containing the translation key.

<span class="localize-me" data-key="someKey"></span>

To replace these tags in your HTML, call the replaceAll() method. You can override the default class name by setting replacementClassName: 'foo' in the options hash.

// Default, basic usage
Localization.replaceAll();

// Substitute an alternate class name and dictionary context
Localization.replaceAll({
  replacementClassName: 'change-this',
  replacementModule: 'UI-BASIC'
});

Text replacement in Handlebars/Ember

Text localization is as simple as invoking the localize helper in your handlebars templates. Localize.js does the rest.

{{localize "someKey"}}

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.