Katipo007/jloc

hello,there

Closed this issue · 3 comments

Hello, I am a Chinese, my English is very poor, I use Google translation to write. I still can't understand how to use it. I want to learn about your localization. Can you make a detailed document description. Moreover, the case lacks room and cannot be operated.

Hi!

This library provides localisation functionality through JSON files

I didn't provide any rooms because this library is designed to fit into existing projects, but you should be able to get it running by creating an object and room yourself.

Here is a quick and basic example:

Example

Create an object with the following events/code:

// create event
jloc_initialise(); // initialises the library

// 'E' key press
jloc_load("english"); // load the English language file

// 'C' key press
jloc_load("chinese"); // load the Chinese language file

// draw event
draw_text(20, 20, jloc_translate("test.hello"))

In 'Included Files':

  1. Add a folder called "localisation"
  2. Inside of the "localisation" folder create two JSON files, "english.json" and "chinese.json"

The "english.json" file should contain:

{
    "test": {
        "hello": "Hello"
    }
}

The "chinese.json" file should contain:

{
    "test": {
        "hello": "你好"
    }
}

When you run the game, press 'E' and 'C' to change between the languages.
Hopefully that can get you started, comment here again if you still need some for help.

I'll mark this issue as resolved for now, but I'll also point out that the library provides some error checking functionality.

Example

// check for errors which may occur when loading the "english" localisation file.
var jloc_error = jloc_load("english");
if (jloc_error == JLOC_e_error.no_error) {
    // no errors!
    show_debug_message("Localisation loaded successfully");
}
else if (jloc_error == JLOC_e_error.not_initialised) {
    show_error("jloc_initialise() must be called before other function usage!", true);
}
else if (jloc_error == JLOC_e_error.file_not_found) {
    show_error("Language file could not be found.", false);
}
else if (jloc_error == JLOC_e_error.file_read_error) {
    show_error("Error reading localisation file.", false);
}
else if (jloc_error == JLOC_e_error.json_parse_error){
    show_error("Error parsing localisation file: Bad JSON structure, please check the file for errors.", false);
}