Giter Club home page Giter Club logo

phaser-i18next's Introduction

Phaser i18next

Phaser i18next is a plugin for Phaser that allows you to have seamless translations in your game. It uses i18next as it's source for translations management, which is widely adopted by the JS community in other projects as well.

Key features:

  • Support for translations namespaces
  • Simple key/value JSON
  • Seamless switching of languages
  • No extra function calls for translating strings, directly build into Phaser's Text object

Getting Started

First you want to get a fresh copy of the plugin. You can get it from this repo or from npm, ain't that handy.

npm install @azerion/phaser-i18next --save-dev

Next up you'd want to add it to your list of js sources you load into your game

//Local installed version
<script src="node_modules/@azerion/phaser-i18next/build/phaser-i18next.js"></script>
//Or use our cdn:
<script src="//cdn.fbrq.io/phaser-i18next/v0.0.1/phaser-i18next.min.js"></script>

After adding the script to the page you can activate it by enabling the plugin:

// Load the plugin with the options, for more details on all possible options, see: http://i18next.github.io/i18next/pages/doc_init.html
game.plugins.add(PhaserI18n.Plugin, {
    fallbackLng: 'en',
    backend: {
        // The path from which we can load the translations, by default this path also includes the translation namespace.
        // Since we only have one namespace, we'll skip this for now.
        loadPath: '/locales/{{lng}}.json'
    }
});

Please note that the backend config in the above example is required for the correct working of i18next with Phaser. The loadPath itself can be anything you want as per i18next documentation, but it's required to be set!

Usage

First up, you need to preload the languages you wish to have in the game.

// Here we preload all the locales for our game.
game.load.locale(
    // All the languages we support: (en, de, nl).
    languages,
    // The namespaces on which the translations are handled, defaults to ['translation'].
    ['translation']
);

i18next plugins

i18next has a very nice set of plugins you can use in order to enhance your i18n experience. You can still leverage the power of these plugins by passing them when you load this Phaser Plugin. All features should work out of the box. You can pass an indefinite amount of plugins to the plugin constructor, just be mindfull that the first argument should be the i18n config:

            //Load the plugin with the options, for more details on all possible options, see: http://i18next.github.io/i18next/pages/doc_init.html
            game.plugins.add(PhaserI18n.Plugin, {
                    //Configure the language we fall back to (defaults to 'dev')
                    fallbackLng: 'en',
                    debug: true,
                    load: 'languageOnly'
                },
                //From here we can add any i18next plugin we'd like to use, new plugins can be added comma-seperated
                window.i18nextBrowserLanguageDetector
            );

Manage translations

When you're all done and set up for translations and have your key value file, next up is starting to translate them. For smaller games this is fairly simple and still manageable by editing your translations in a text file. But when you start with bigger games and more translations (and translation namespaces) you want to manage your translations better and maybe even use external translator services.

Two of those service you could use are locize and/or Poeditor. Both these services allow you to online edit key value JSON translations that are used in i18next. The advantage of using such tools is that it's easier to allow external people work on your translations and they aggregate the statistics of your projects (translation completion, languages managed, etc.)

Disclaimer

We at Azerion just love playing and creating awesome games. We aren't affiliated with Phaser.io or i18next. We just needed some awesome translations in our awesome HTML5 games. Feel free to use it for enhancing your own awesome games!

Phaser i18next is distributed under the MIT license. All 3rd party libraries and components are distributed under their respective license terms.

phaser-i18next's People

Contributors

alebles avatar dreadknight avatar florisdh avatar muescha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

phaser-i18next's Issues

Plurals with interpolations

Currently, plurals with interpolations is not implemented in this library.
It is a handy feature and would be quite nice to have.

Can this please be added as a new feature?

See i18next for more info.

Typo in function name

Function setTranslationParamameter has a typo.
It should be setTranslationParameter.

Uncaught TypeError

This error comes directly when mounting, I use version 1.0.3:

phaser-i18next.js:2198 Uncaught TypeError: Object prototype may only be an Object or null: undefined
    at setPrototypeOf (<anonymous>)
    at __extends (phaser-i18next.js:2198)
    at phaser-i18next.js:2247
    at phaser-i18next.js:2341
    at phaser-i18next.js:2343

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.