Code Monkey home page Code Monkey logo

cakephp-i18njs's Introduction

I18nJs Plugin for CakePHP

A CakePHP 2.x plugin to translate JavaScript strings. The JavaScript functions and methods to fetch the translation strings are taken from Drupal 8.

How to include

  • Put the files in APP/Plugin/I18nJs
  • Make sure you have CakePlugin::load('I18nJs') or CakePlugin::loadAll() in your bootstrap
  • Include the JavaScript lib to your HTML $this->Html->script('/i18n_js/js/18n_js')
  • Add generated JavaScript translation file $this->Html->script('/js/Locale/i18n_js.' . $this->Session->read('Config.language'))

JavaScript functions

I18nJs.t(str, args, options)

Translate strings to the page language or a given language.

Examples:

I18nJs.t('This string needs transalation');
I18nJs.t('Welcome @name', {'@name': 'Wouter'});

I18nJs.t(count, singular, plural, args, options)

Format a string containing a count of items.

Examples:

Drupal.formatPlural(count, '@name has 1 site.', '@name has @count sites.', {'@name': personName});
Drupal.formatPlural(count, '1 comment', '@count comments');

Generate .pot file

Console/cake I18nJs.i18n_js extract_js

This will parse all the javascript translation functions from your .js and .ctp files. This will create the file App/Locale/i18n_js.pot.

Create JavaScript translation file

Make sure your translations are located in App/Locale/<language>/LC_MESSAGES/i18n_js.po.

Console/cake I18nJs.i18n_js generate_js

This will create JavaScript file(s) as App/webroot/js/Locale/i18n_js.<language>.js.

This fill should be added to your HTML. Add for example the following to your default.ctp file:

echo $this->Html->script('/js/Locale/i18n_js.' . $this->Session->read('Config.language'));

cakephp-i18njs's People

Contributors

kim-dongit avatar wvdongen avatar

Watchers

 avatar  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.