@koreez/phaser3-i18n
TypeScript icon, indicating that this package has built-in type declarations

2.0.6 • Public • Published

Phaser3 i18n Plugin

GitHub license Build Status codebeat badge Test Coverage npm version Greenkeeper badge styled with prettier

Phaser3 i18n is a plugin for Phaser 3 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

Installation

npm

$ npm i -g npm
$ npm i --save  @koreez/phaser3-i18n

Usage

Import the plugin

import { I18nPlugin } from "@koreez/phaser3-i18n";

Load the plugin

You need to load the plugin in your game. This is done just like any other plugin in Phaser 3. So, to load the plugin, include it in plugins config.

const config = {
    type: Phaser.AUTO,
    parent: "phaser-example",
    width: 800,
    height: 600,
    plugins: {
        scene: [
            {
                key: "i18nPlugin",
                plugin: I18nPlugin,
                mapping: "i18n"
            }
        ]
    },
    scene: {
        create: create
    }
};

Initialize the plugin

After plugin has been loaded you need to initialize it.

create () {
  this.i18n.initialize(
    {
      fallbackLng: 'en',
      loadPath: 'assets/i18n/{{lng}}/{{ns}}.json',
      debug: false,
    },
    function () {
      console.log('I18nPlugin initialized!')
    },
  )
}

The plugin will patch add.text, add.bitmapText and add.dynamicBitmapText / make.text, make.bitmapText and make.dynamicBitmapText methods with additional functionality.

Create localized texts

// x - any
// y - any
// font - bitmap font
// text - should be translation key
// size - font size
// interpolations - interpolation for translation (for example { 0: "value0", 1: "value1" }), note this is not required parameter
this.add.bitmapText(x, y, font, text, size, interpolations);
or via config
var config = {
    x: 100,
    y: 100,
    text: "translationKey",
    font: "atari-classic",
    size: 64,
    interpolations: { 0: "value0", 1: "value1" }
};
this.make.dynamicBitmapText(config);

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

Credits

Big thanks to this great repo:

https://github.com/orange-games/phaser-i18next

License

MIT

Package Sidebar

Install

npm i @koreez/phaser3-i18n

Weekly Downloads

8

Version

2.0.6

License

MIT

Unpacked Size

4.12 MB

Total Files

37

Last publish

Collaborators

  • arturvardanyan
  • gnun
  • saqsun
  • avagyanah