//============================================================================= // NRP_MultiLanguage.js //============================================================================= /*: * @target MZ * @plugindesc v1.06 Multi-language support. * @author Takeshi Sunagawa (http://newrpg.seesaa.net/) * @url https://newrpg.seesaa.net/article/521162546.html * * @help This plugin adds multi-language support to RPG Maker MZ. * * Main features: * - Load text from xlsx or LibreOffice Calc ods files * and replace it by language. * - Load database JSON files and plugin parameters * from language projects. * - Automatically switch between registered images * based on the selected language. * - Add a language-selection command to the Options screen. * - Integrate with the MZ Text Editor extension. * * Microsoft Excel is not required. * Any spreadsheet application that can save xlsx or ods files, * such as LibreOffice, can be used. * * Note: Please place this plugin as high up in the list as possible. * Only plugins listed below this one will be translated. * * ------------------------------------------------------------------- * [xlsx file placement] * ------------------------------------------------------------------- * Place xlsx or ods files in [Project]/data/localize/. * Both formats use the same sheet layout. In the explanations below, * references to xlsx also apply to ods. * Do not keep duplicate translations in both formats: later files overwrite * entries with the same sheet name and ID. * Regenerate FILE_LIST.json after changing files for browser releases. * * If you look at the sample, * you should get a general idea of the format. * Details are provided below. * * ◆xlsx Format * - The first row is the header row. * - The “ID” column serves as the key * for referencing entries within the text. * - The language code columns (ja, en, etc.) * correspond to the text columns for each language. * - From the second row onward: * Enter an ID in the “ID” column (e.g., 001) * and the corresponding text in the respective language columns. * - The order of the columns is flexible. * You may also add reference information, * such as the speaker, as a column. * * ◆Specifying Sheet Names * This plugin supports multiple XLSX files and multiple sheets. * However, only the sheet name is used as the key. * If the same sheet name is used across multiple files, * it will be invalid. * Note: Sheet names are not case-sensitive. * * - When using multiple sheets, * separate the names with a period (.) at the beginning. * (Example: If the sheet name is “town001” and the ID is “001” * enter “town01.001”) * - You can also omit the sheet name by setting the current sheet name. * There are two ways to set the current sheet name: * - Set it in the map’s notes field * as follows: * - Set a string in the “Sheet Name Variable” * plugin parameter using a script. * - Note that if only one sheet is used throughout the project, * this can be omitted. * * ------------------------------------------------------------------- * [Translation Overview] * ------------------------------------------------------------------- * This plugin offers various methods for multilingual support. * Please choose the method that works best for you. * * - Main text: \lanm * - Name field: \lanc, or refer to a separate project * (TextScriptBase.js) * - Options: \lanc * - Database: Refer to a separate project * - Plugin parameters: Refer to a separate project * * I recommend using these as appropriate. * Details are explained below. * * ------------------------------------------------------------------- * [Text replacement with xlsx] * ------------------------------------------------------------------- * ◆String Replacement (\lan[id]) * * This is the simplest method. * It replaces the text with the language specified in the xlsx file. * It can be used for body text, name fields, * database fields, plugin parameters, and more. * * However, the text entered in the editor * must consist solely of control characters. * Please note that when viewed in the editor, * only the code will be visible. * * ◆Replace text based on the “Name” field (\lanm[id]) * * Entering text in the “Name” field will replace the body text * with the corresponding language specified in the XLSX file. * If no corresponding language is specified, * the original text will be used as is. * * This is useful when you want to make a project * that has already been completed in Japanese * multilingual while making as few changes as possible. * * ◆String Prefix Replacement (\lanc[id]) * * Replaces the text at the beginning of the input field * with the corresponding language specified in xlsx. * Can be used for body text, name fields, database fields, * plugin parameters, and more. * If the corresponding language is not available, * the original text is used as-is. * * This is also useful when you want to make * a project—already completed as an English-language work— * multilingual with as few changes as possible. * It can also be used for replacements * in name fields and drop-down menus. * * ◆Automatic Replacement * * If you specify an xlsx file as the “Automatic Replacement File,” * text that matches the entries in the “Name” column * and the “Options” column will be automatically replaced. * It also supports strings expanded using \v[] * and similar constructs (for the “Name” column only). * * This feature uses the “original” column in the xlsx file as the key. * * Example (original column = “Alex”, ja column = “アレックス”): * Name field “Alex” → “アレックス” in Japanese * * ◆Script * * If you want to reference it from a script, * you can use the following function. * Note1: Please note that you must pass the ID as a string. * Note2: The rules for sheet names, etc., are the same as for \lan[id]. * * $lan(id) * Example: $lan("town01.001") * * You can also specify a string to display if no matches are found. * This is useful if you don't want Excel to retain * the original language values. * * $lan(id, Default Value) * Example: $lan("town01.001", "Hello!") * * ------------------------------------------------------------------- * [Language projects] * ------------------------------------------------------------------- * By creating a separate project for each language, * you can reference the corresponding text when switching languages. * This applies to database and plugin parameters. * Note: Map data and assets are not referenced. * * Please create a separate project for the language. * The database applies to text fields (including the “Note” field). * Plugin parameters apply to all fields. * Only fields with data will be overwritten; * all others will be ignored. * It is safer to delete any unnecessary plugins or plugin parameters. * Please be careful not to accidentally * overwrite the note field in the database. * * ※For example, it is possible to adjust * layout-related parameters based on the language. * * Please register the relevant “Language Code,” * “Locale,” “Folder Name,” and “Language Project Path” * in the “Language List” section of the plugin parameters. * * When you run a test playthrough, the respective JSON files and * plugins.js (plugin parameters) will be copied automatically. * * ◆Note Tag Merge * You can change the settings so that the note field * is overwritten for each tag. * For example, suppose the note field for * a certain enemy contained the following specification: * * * * * Of these, only needs to be multilingual. * If you enable merging of enemy note tags, * you’ll only need to include in the language project. * * ◆Terminology Plugins * To replace text in the name field, * you can use a terminology plugin. * You can use the official plugin “TextScriptBase.js,” for example. * * ------------------------------------------------------------------- * [Auto Image Switching] * ------------------------------------------------------------------- * Images are automatically switched based * on the current language code. * You can specify the images to be used * in the “Image List” and “Pattern List.” * * For example, if you specify “img\pictures\Test.png” * the system will automatically display * “img\pictures\ja\Test.png” if the language is Japanese. * * This also applies when using subfolders. * “img\pictures\Help\Test.png” will be replaced with * “img\pictures\ja\Help\Test.png”. * * The “Pattern List” is a handy feature * for specifying multiple files. * * ◆This applies to files in the “pictures\Help” directory * pictures\Help\* * * ◆Includes subfolders even further down the hierarchy * pictures\Help\** * * If the target image does not exist, * the original image will be used. * Please note that in this case, * there will be a slight delay in the image display. * (To verify the file's existence) * * ------------------------------------------------------------------- * [Create Fast JSON] * ------------------------------------------------------------------- * When enabled, language-specific * JSON files (e.g.:LANG_en.json) and a cache JSON file * are generated in "data/localize/json/" during test play. * * While parsing the xlsx/ods files takes time during * the initial generation or when translation data is modified, * this process significantly reduces load times * in the production environment. * * Additionally, enabling this feature * allows the application to run in a browser. * Please ensure this feature is turned on when launching in a browser. * * Due to the system's design, if you modify * the translation data (xlsx/ods) and upload the production files * without first performing a test launch, * the changes will not be correctly reflected. * ※Though it is highly unlikely that this would happen... * * ------------------------------------------------------------------- * [Other Details] * ------------------------------------------------------------------- * ◆Language Code Storage Location * The current language code is loaded * from the following locations when the game starts. * ・Local environment: save/nrp_language.ini * ・Browser environment: the “nrp_language” key in localStorage * This is managed independently of config.rmmzsave. * * ◆Behavior When Switching Languages * If you switch the language in the Options menu * on the title screen and then close the Options menu, * the game will restart after saving the language code. * The language settings are grayed out * and cannot be changed anywhere other than the title screen. * * ◆Language Variable * Language variable is automatically reset * when you start a new game or load a saved game. * * ------------------------------------------------------------------- * [SheetJS setup] * ------------------------------------------------------------------- * 1. Download xlsx.full.min.js from: * https://cdn.sheetjs.com/xlsx-0.20.3/package/dist/xlsx.full.min.js * * 2. Place it at [Project]/js/libs/xlsx.full.min.js. * * ------------------------------------------------------------------- * [Terms] (SheetJS) * ------------------------------------------------------------------- * This plugin uses SheetJS Community Edition. * If you distribute or sell this as a game, * please include the following in the credits or * in the text included with the game. * * SheetJS Community Edition -- https://sheetjs.com/ * Copyright (C) 2012-present SheetJS LLC * Licensed under the Apache License, Version 2.0 * https://www.apache.org/licenses/LICENSE-2.0 * * ◆Add * According to the official Apache License documentation, * it seems they recommend creating a license file rather than * including the text directly. * I've created one for SheetJS below; just place it somewhere * in your project where it can be referenced, and you're all set. * * https://newrpg.up.seesaa.net/image/SheetJS-LICENSE.txt * * ------------------------------------------------------------------- * [Terms] (NRP_MultiLanguage.js) * ------------------------------------------------------------------- * There are no restrictions. * Modification, redistribution freedom, commercial availability, * and rights indication are also optional. * The author is not responsible, * but will deal with defects to the extent possible. * * @------------------------------------------------------------------ * @ Plugin Parameters * @------------------------------------------------------------------ * * @param LanguageList * @text Language List * @type struct[] * @default ["{\"LangNo\":\"0\",\"LangName\":\"English\",\"LangCode\":\"en\",\"Locale\":\"en_US\",\"FolderName\":\"\",\"LangProjectPath\":\"\"}","{\"LangNo\":\"1\",\"LangName\":\"Japanese\",\"LangCode\":\"ja\",\"Locale\":\"ja_JP\",\"FolderName\":\"data_ja\",\"LangProjectPath\":\"\"}"] * @desc Configure the languages available to the player. * * @param LanguageVariable * @text Language Variable * @type variable * @default 0 * @desc Stores the current language number. Set 0 to disable this feature. * * @param SheetVariable * @text Sheet Variable * @type variable * @default 0 * @desc Stores the current xlsx sheet name used by \lan[ID]. * Set a map note to change it automatically. * * @param DefaultSheetName * @parent SheetVariable * @text Default Sheet Name * @type string * @default * @desc Default sheet name. A blank value is valid. It takes priority over * automatic selection when there is only one xlsx sheet. * * @param DefaultLanguage * @text Default Language * @type select * @option Japanese @value ja * @option English @value en * @option Chinese (Simplified) @value zh-CN * @option Chinese (Traditional) @value zh-TW * @option Korean @value ko * @option French @value fr * @option German @value de * @option Spanish @value es * @option Italian @value it * @option Portuguese @value pt * @option Russian @value ru * @option Arabic @value ar * @option Turkish @value tr * @option Dutch @value nl * @option Polish @value pl * @option Swedish @value sv * @option Norwegian @value no * @option Danish @value da * @option Finnish @value fi * @option Czech @value cs * @option Hungarian @value hu * @default en * @desc Used when the OS language does not match an entry in Language List. * Also used on the first launch. * * @param OriginalLanguage * @text Original Language * @type select * @option Japanese @value ja * @option English @value en * @option Chinese (Simplified) @value zh-CN * @option Chinese (Traditional) @value zh-TW * @option Korean @value ko * @option French @value fr * @option German @value de * @option Spanish @value es * @option Italian @value it * @option Portuguese @value pt * @option Russian @value ru * @option Arabic @value ar * @option Turkish @value tr * @option Dutch @value nl * @option Polish @value pl * @option Swedish @value sv * @option Norwegian @value no * @option Danish @value da * @option Finnish @value fi * @option Czech @value cs * @option Hungarian @value hu * @default en * @desc The source language of this project. Images are not switched when it matches the current language. * * @param SkipXlsxForOriginalLanguage * @text Skip xlsx for Original Language * @type boolean * @default false * @desc Skip SheetJS and xlsx/ods loading when the current language is the original language. * * @param MakeFastJson * @text Create Fast JSON * @type boolean * @default true * @desc Generate per-language JSON during test play. Include the generated JSON in releases. * * @param DisableFeature * @text [Dev]Disable Feature * @type boolean * @default false * @desc This will disable the features of this plugin. * Use this if you want to disable a feature during development. * * @param