设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 72|回复: 0

[转载发布] Iavra_MasterLocalization

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    8037

    主题

    864

    回帖

    3万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    30081
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    39012

    灌水之王

    发表于 5 天前 | 显示全部楼层 |阅读模式
    Spoiler:  MODERATORS AND IAVRA(PLUGIN AUTHOR)
    I have not made this plugin. This is a fusion of the two @Iavra plugins: LocalizationCore and LocalizationMenu.
    I have made this when I was learning how to code and so I rewrite a little bit of this plugin in a way that I can understand it better.
    I have fixed a bug that when having more than 3 languages, the options to select behave strangely and add a fix inside the plugin that the author himself had made. Also, add plugin commands.
    If the Author or the moderators do not agree with this post, please don't approve it. As well I will remove it from Itch Io too.
    I also made a demo of the plugin working and it will all be free for the public.

    Author: Iavra
    *No longer supported*


    Introduction

    This plugin is the merger of two plugins from the Iavra author: Iavra_Localization_Core and Iavra_Localization_Menu. I didn't change anything in the codes, I just changed the way it is written.
    Three bugs were fixed, two by me and one by the author himself in the topic official.
    There were also some changes to the help file.

    Features

    • Add as many languages as you want.
    • Make translations using an external .json file and import it into the game.
    • You can translate the entire database.
    • You can also translate anything into the parameters of other plugins.
    • Change the language through the menu or script calls.
    • Works on Pc and Mobile.

    How to use

    • Setting the languages:
    First, set your languages in the "Languages" parameter.
    Then make the files .json (Must be saved in UTF-8) in your favorite text
    editor and name them according to the parameter.

    Example:
    Parameter > en, ptbr, esp
    Files > en.json, ptbr.json, esp.json

    These files must be in the project's root folder.

    The first language defined will be the default language.

    • How translation works:
    The plugin will replace an "escape code" that you use in the game for what matches it in the .json files.

    Example:
    Message box> # {Npc.01} or # {Npc01}

    In the .json file for the languages you should put it like this:

    "Npc": {
    "01": "My name is Haroldo",
    "02": "My name is Laura"
    }

    or

    "Npc01": "My name is Haroldo"

    You can repeat the same process in the database and parameters of other plugins.
    You can also translate using arrays:

    In .json:
    "text": ["Text 1", "Text 2", "Text 3"]
    This will generate escape codes> "text.0", "text.1" and "text.2"

    Escape codes can also contain other escape codes within them:
    {
    "text": "Hi, my name is # {actor}",
    "actor": "Harold"
    }

    * Do not use accents in the "escape code".

    * To use the default escape codes of the message box (including other plugins):
    Wrong > \ i [2]
    Right > \\ i [2]

    * To skip a line use \n, as the .json file by default does not support
    line break.

    The plugin offers the following script calls:

    IAVRA.MasterLocalization.I18N.language;         Returns the current language.
    IAVRA.MasterLocalization.I18N.language = lang;  Sets the current language to lang.
    IAVRA.MasterLocalization.I18N.languages();      Returns a list of all available languages.
    IAVRA.MasterLocalization.I18N.localize(text);   Localizes the given text.

    You can change the languages via menu > options, via script calls or with the plugin command:

    SET_LANG [language]

    Example:

    SET_LANG en

    *You can use this site to find and fix errors in .json files:


    JSON Formatter & Validator

    Format and validate JSON data so that it can easily be read by human beings.

                                            jsonformatter.curiousconcept.com                               





    Screenshots
    Spoiler
















    Terms of Use

    Free for commercial and non-commercial.
    As long you credit Iavra.
    Original thread.


    Spoiler: IAVRA_MasterLocalization.js
                    JavaScript:       
    1. //============================================================================
    2. // IAVRA_MasterLocalization.js
    3. //============================================================================
    4. /*:
    5. @plugindesc Fusion of Iavra Localization Core and Menu, with bug fixes.
    6. <Iavra Master Localization>
    7. @author Iavra
    8. @param Escape Code
    9. @type text
    10. @desc Code, that will be used to retrieve localized strings. "{key}" serves as placeholder for the text key. It's better leave it alone.
    11. @default #{{key}}
    12. @param Languages
    13. @type text
    14. @desc Comma-separated list of languages, that should be supported. The first entry will be used as the default.
    15. @default en, ptbr, esp
    16. @param File Path
    17. @type text
    18. @desc Path to the language files to load. The sequence "{lang}" will be replaced with the languages entered above. It's better leave it alone.
    19. @default {lang}.json
    20. @param Option Label
    21. @type text
    22. @desc Label to be used for the option in the options menu.
    23. @default Language
    24. @param Language Labels
    25. @type text
    26. @desc Comma-separated list of "language:label" pairs, to be used for the language selection.
    27. @default en:English, ptbr:Portuguese
    28. @help
    29. ==============================================================================
    30. Introduction
    31. ==============================================================================
    32. This plugin is the merger of two plugins from the Iavra author:
    33. Iavra_Localization_Core and Iavra_Localization_Menu. I didn't change anything
    34. in the codes, I just changed the way it is written.
    35. Three bugs were fixed, two by me and one by the author himself in the topic
    36. official. There were also some changes to the help file.
    37. ==============================================================================
    38. Features
    39. ==============================================================================
    40. • Add as many languages as you want.
    41. • Make translations using an external .json file and import it into the game.
    42. • You can translate the entire database.
    43. • You can also translate anything into the parameters of other plugins.
    44. • Change the language through the menu or script calls.
    45. • Works on Pc and Mobile.
    46. ==============================================================================
    47. How to use
    48. ==============================================================================
    49. • Setting the languages:
    50. First, set your languages in the "Languages" parameter.
    51. Then make the files .json (Must be saved in UTF-8) in your favorite text
    52. editor and name them according to the parameter.
    53. Example:
    54. Parameter > en, ptbr, esp
    55. Files > en.json, ptbr.json, esp.json
    56. These files must be in the project's root folder.
    57. The first language defined will be the default language.
    58. • How translation works:
    59. The plugin will replace an "escape code" that you use in the game for what
    60. matches it in the .json files.
    61. Example:
    62. Message box> # {Npc.01} or # {Npc01}
    63. In the .json file for the languages you should put it like this:
    64. "Npc": {
    65. "01": "My name is Haroldo",
    66. "02": "My name is Laura"
    67. }
    68. or
    69. "Npc01": "My name is Haroldo"
    70. You can repeat the same process in the database and parameters of other
    71. plugins.
    72. You can also translate using arrays:
    73. In .json:
    74. "text": ["Text 1", "Text 2", "Text 3"]
    75. This will generate escape codes> "text.0", "text.1" and "text.2"
    76. Escape codes can also contain other escape codes within them:
    77. {
    78. "text": "Hi, my name is # {actor}",
    79. "actor": "Harold"
    80. }
    81. * Do not use accents in the "escape code".
    82. * To use the default escape codes of the message box (including other
    83. plugins):
    84. Wrong > \ i [2]
    85. Right > \\ i [2]
    86. * To skip a line use \n, as the .json file by default does not support
    87. line break.
    88. The plugin offers the following script calls:
    89. IAVRA.MasterLocalization.I18N.language;         Returns the current language.
    90. IAVRA.MasterLocalization.I18N.language = lang;  Sets the current language to lang.
    91. IAVRA.MasterLocalization.I18N.languages();      Returns a list of all available languages.
    92. IAVRA.MasterLocalization.I18N.localize(text);   Localizes the given text.
    93. You can change the languages via menu > options, via script calls or with
    94. the plugin command:
    95. SET_LANG [language]
    96. Example:
    97. SET_LANG en
    98. *You can use this site to find and fix erros in .json files:
    99. https://jsonformatter.curiousconcept.com/
    100. ==============================================================================
    101. Terms of Use
    102. ==============================================================================
    103. Free for commercial and non-commercial. As long you credit Iavra.
    104. Original thread:
    105. https://forums.rpgmakerweb.com/index.php?threads/iavra-localization.53699/
    106. If you want, can give credits to me(Eliaquim) too ^^
    107. ==============================================================================
    108. Updatelog
    109. ==============================================================================
    110. Version 1.0 - 04/10/2020
    111. - Released!
    112. */
    113. /*:pt
    114. @plugindesc Plugin para adicionar traduções ao jogo por meio de arquivo externo.
    115. <Iavra Localization Core>
    116. @author Iavra
    117. @param Escape Code
    118. @type text
    119. @desc O código modelo para usar para tradução. Substitua o "key" pela string desejada. Melhor não alterar isso.
    120. @default #{{key}}
    121. @param Languages
    122. @type text
    123. @desc Coloque aqui as linguagens que deseja usar no jogo. A primeira da lista será a padrão. Separe-as com ", "(Sem aspas).
    124. @default en, ptbr, esp
    125. @param File Path
    126. @type text
    127. @desc Melhor não mexer nisso.
    128. @default {lang}.json
    129. @param Option Label
    130. @type text
    131. @desc Nome da opção para troca de idioma no menu de opções.
    132. @default Language
    133. @param Language Labels
    134. @type text
    135. @desc Como cada idioma irá aparecer no menu de opções. Formato "idioma:NomeDaOpção".Separe com vírgula e espaço.
    136. @default en:English, ptbr:Portuguese
    137. @help
    138. ==============================================================================
    139. Introdução
    140. ==============================================================================
    141. Esse plugin é a fusão de dois plugins do autor Iavra: Iavra_Localization_Core
    142. e Iavra_Localization_Menu. Eu não alterei nada nos códigos, apenas mudei a
    143. forma como é escrito.
    144. Foram consertados três bugs, dois por mim e outro pelo próprio autor no tópico
    145. oficial. Também houveram algumas mudanças no arquivo de ajuda.
    146. ==============================================================================
    147. Funcionalidades
    148. ==============================================================================
    149. • Adicione quantos idiomas quiser.
    150. • Faça as traduções por um arquivo externo .json e importe para o jogo.
    151. • Você pode traduzir todo o database.
    152. • Também pode traduzir qualquer coisa nos parâmetros de outros plugins.
    153. • Mude a linguagem através do menu ou de script calls.
    154. • Funciona em Pc e Mobile.
    155. ==============================================================================
    156. Como usar
    157. ==============================================================================
    158. • Definindo os idiomas:
    159. Primeiro defina seus idiomas no parâmetro "Languages". Depois faça os arquivos
    160. .json(Devem ser salvos em UTF-8) no seu editor de texto favorito e nomeie-os
    161. de acordo com o preenchimento do parâmetro.
    162. Exemplo:
    163. Parâmetro > en, ptbr, esp
    164. Arquivos > en.json, ptbr.json, esp.json
    165. Esses arquivos devem estar na pasta raiz do projeto.
    166. A primeira linguagem definida será a linguagem padrão.
    167. • Como funciona a tradução:
    168. O plugin irá substituir um "escape code" que você usar no jogo para o que
    169. estiver correspondente a ele nos arquivos .json.
    170. Exemplo:
    171. Caixa de mensagens > #{Npc.01} ou #{Npc01}
    172. No arquivo .json dos idiomas você deverá colocar assim:
    173. "Npc": {
    174.     "01":"Meu nome é Haroldo",
    175.     "02":"Meu nome é Laura"
    176. }
    177. ou
    178. "Npc01":"Meu nome é Haroldo"
    179. Poderá repetir o mesmo procedimento no database e parâmetros de outros plugins.
    180. Você também pode traduzir usando arrays:
    181. No .json:
    182. "text": ["Text 1", "Text 2", "Text 3"]
    183. Isso vai gerar os escape codes > "text.0", "text.1" and "text.2"
    184. Os escape codes também podem conter outros escape codes dentro deles:
    185. {
    186. "text": "Hi, my name is #{actor}",
    187. "actor": "Harold"
    188. }
    189. *Não use acentos no "escape code".
    190. *Para usar os escape codes default da caixa de mensagens(incluindo de outros
    191. plugins):
    192. Errado > \i[2]
    193. Certo > \\i[2]
    194. *Para pular uma linha use \n, já que o arquivo .json por padrão não suporta
    195. quebra de linha.
    196. O plugin oferece os seguintes script calls:
    197. IAVRA.MasterLocalization.I18N.language;           Retorna o idioma atual.
    198. IAVRA.MasterLocalization.I18N.language = "lang";  Muda o idioma para outro idioma "lang".
    199. IAVRA.MasterLocalization.I18N.languages();        Retorna uma lista de todos os idiomas.
    200. IAVRA.MasterLocalization.I18N.localize(text);     Localiza o texto desejado.
    201. Você pode mudar um idioma através do menu de opções, pelos script calls
    202. acima ou pelo comando de plugin:
    203. SET_LANG [idioma]
    204. Exemplo:
    205. SET_LANG ptbr
    206. *Você pode usar esse site para corrigir erros de formatação no arquivo .json
    207. https://jsonformatter.curiousconcept.com/
    208. ==============================================================================
    209. Termos de uso
    210. ==============================================================================
    211. Livre para projetos comerciais e não comerciais, contanto que seja dado
    212. créditos para Iavra.
    213. Link do tópico oficial feito pelo autor:
    214. https://forums.rpgmakerweb.com/index.php?threads/iavra-localization.53699/
    215. Se quiser, pode me dar créditos também(Eliaquim).
    216. ==============================================================================
    217. Updatelog
    218. ==============================================================================
    219. Versão 1.0 - 10/04/2020
    220. - Released
    221. */
    222. "use strict";
    223. var Imported = Imported || {};
    224. Imported.IAVRA_MasterLocalization = true;
    225. var IAVRA = IAVRA || {};
    226. IAVRA.MasterLocalization = IAVRA.MasterLocalization || {};
    227. IAVRA.MasterLocalization.Parameters = PluginManager.parameters('IAVRA_MasterLocalization');
    228. IAVRA.MasterLocalization.Param = IAVRA.MasterLocalization.Param || {};
    229. IAVRA.MasterLocalization.Param = {
    230.     EscapeCode: String(IAVRA.MasterLocalization.Parameters['Escape Code']),
    231.     IvCoreLanguages: String(IAVRA.MasterLocalization.Parameters['Languages']).split(/\s*,\s*/).filter(function(lang) { return !!lang; }),
    232.     IvCoreFilePath: String(IAVRA.MasterLocalization.Parameters['File Path']),
    233.     IvCoreLabelOption: String(IAVRA.MasterLocalization.Parameters['Option Label']),
    234.     IvCoreLabelLanguages: String(IAVRA.MasterLocalization.Parameters['Language Labels']).split(/\s*,\s*/).reduce(function(map, entry) {
    235.     var split = entry.split(':');
    236.     if(split.length === 2) {
    237.     map[split[0]] = split[1];
    238.     }
    239.     return map;
    240.     }, {})
    241. }
    242. /**
    243. * Regex used to replace escape codes with localized data.
    244. */
    245. var IvCoreRegex = new RegExp(IAVRA.MasterLocalization.Param.EscapeCode.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&").replace('\\{key\\}', '([\\w\\.]+?)'), 'g');
    246. /**
    247. * The current language.
    248. */
    249. var IvCoreLang = IAVRA.MasterLocalization.Param.IvCoreLanguages[0];
    250. /**
    251. * Contains all localized data read from the data files defined "File Path". We intentionally don't use the object
    252. * literal {}, but create a new Object with a null prototype, so we don't inherit any properties.
    253. */
    254. var IvCoreData = IAVRA.MasterLocalization.Param.IvCoreLanguages.reduce(function(map, lang) { map[lang] = null; return map; }, Object.create(null));
    255. /**
    256. * Indicated, whether we are currently inside of "drawTextEx". Not thread-/async-safe!
    257. */
    258. var IvCoreinDrawTextEx = false;
    259. /**
    260. * Initializes the language data by reading all files and storing their content inside the _data object. The
    261. * undefined data serves as fallback, if no language is given in the "Languages" plugin parameter.
    262. */
    263. function IvCoreInitialize() {
    264.     IAVRA.MasterLocalization.Param.IvCoreLanguages.forEach(function(lang) {
    265.         IvCoreLoadFile(IAVRA.MasterLocalization.Param.IvCoreFilePath.replace('{lang}', lang), function(data) {
    266.         IvCoreData[lang] = IvCoreFlatten(data); });
    267.     });
    268. IvCoreData[undefined] = {};
    269. };
    270. /**
    271. * Loads a JSON file and executes the given callback with the parsed file contents as a parameter.
    272. */
    273. function IvCoreLoadFile(url, callback) {
    274.     var request = new XMLHttpRequest();
    275.     request.open('GET', url);
    276.     request.overrideMimeType('application/json');
    277.     request.onload = function() {
    278.         callback(JSON.parse(request.responseText));
    279.     };
    280.     request.onerror = function() {
    281.         throw new Error("There was an error loading the file '" + url + "'.");
    282.     };
    283.     request.send();
    284. };
    285. /**
    286. * Flattens the given data object by joining nested object keys and array indizes with "." and returns a single-
    287. * level object, whose keys can be used in escape codes.
    288. */
    289. function IvCoreFlatten(object) {
    290.     var result = {}, temp, value;
    291.     for(var key in object) {
    292.         if(typeof (value = object[key]) === 'object') {
    293.             temp = IvCoreFlatten(value);
    294.             for(var x in temp) {
    295.                 result[key + '.' + x] = temp[x];
    296.             }
    297.         } else {
    298.             result[key] = value;
    299.         }
    300.     }
    301.     return result;
    302. };
    303. /**
    304. * Returns true, if all language files have been loaded.
    305. */
    306. function IvCoreIsReady() {
    307.     return IAVRA.MasterLocalization.Param.IvCoreLanguages.every(function(lang) {
    308.         return !!IvCoreData[lang];
    309.     });
    310. };
    311. /**
    312. * Recursively replaces all escape codes in the text with the localized data. Note, that we also do an implicit
    313. * conversion of the given data to String, since otherwise the function would crash, when invoked with a number.
    314. */
    315. var IvCoreReplace = function(text) {
    316.     if(text === undefined || text === null) {
    317.         return text;
    318.     }
    319.     var f = true;
    320.     var d = IvCoreData[IvCoreLang];
    321.     var r = '' + text;
    322.     while(f) {
    323.         f = false;
    324.         r = r.replace(IvCoreRegex, function(m, k) {
    325.             f = true; return d[k];
    326.         });
    327.     }
    328.     return r;
    329. };
    330. //=============================================================================
    331. // IAVRA.MasterLocalization.I18N
    332. //=============================================================================
    333. IAVRA.MasterLocalization.I18N = {
    334. /**
    335. * Localizes a given text. Can be used, when the automatic localization happens too late (or not at all):
    336. */
    337. localize: function(text) {
    338.     return IvCoreReplace(text);
    339. },
    340. /**
    341. * Returns the list of all registered languages. Can be used to create an option menu or similar.
    342. */
    343. languages: function() {
    344.     return IAVRA.MasterLocalization.Param.IvCoreLanguages;
    345. }
    346. };
    347. /**
    348. * Property used to read and set the current language. If the given value wasn't registered in the "Languages"
    349. * plugin parameter, fallback to the first language, instead. Also, when changing the language, we need to update
    350. * the document title, since the game title might be localized.
    351. */
    352. Object.defineProperty(IAVRA.MasterLocalization.I18N, 'language', {
    353.     get: function() {
    354.         return IvCoreLang;
    355.     },
    356.     set: function(value) {
    357.         IvCoreLang = IAVRA.MasterLocalization.Param.IvCoreLanguages.contains(value) ? value : IAVRA.MasterLocalization.Param.IvCoreLanguages[0];
    358.         Scene_Boot.prototype.updateDocumentTitle();
    359.     }
    360. });
    361. //=============================================================================
    362. // Scene_Boot(RPG SCENE)
    363. //=============================================================================
    364. /**
    365. * When creating Scene_Boot, also start loading all language files to initialize the plugin.
    366. */
    367. IAVRA.Scene_Boot_create = Scene_Boot.prototype.create;
    368. Scene_Boot.prototype.create = function() {
    369.     IAVRA.Scene_Boot_create.call(this);
    370.     IvCoreInitialize();
    371. };
    372. /**
    373. * Also wait, until all language data has been read.
    374. */
    375. IAVRA.Scene_Boot_isReady = Scene_Boot.prototype.isReady;
    376. Scene_Boot.prototype.isReady = function() {
    377.     return IvCoreIsReady() && IAVRA.Scene_Boot_isReady.call(this);
    378. };
    379. /**
    380. * We override this method, because we may have to convert the game title, before setting the document title.
    381. * Make sure, that $dataSystem is already initialized, because an option menu will set the current language,
    382. * before data has been loaded. But don't worry, the correct title will be set during Scene_Boot.start.
    383. */
    384. IAVRA.Scene_Boot_updateDocumentTitle = Scene_Boot.prototype.updateDocumentTitle;
    385. Scene_Boot.prototype.updateDocumentTitle = function() {
    386.     if($dataSystem) {
    387.         document.title = IvCoreReplace($dataSystem.gameTitle);
    388.     }
    389. };
    390. //=============================================================================
    391. // Window_Base(RPG WINDOWS)
    392. //=============================================================================
    393. /**
    394. * Set a marker indicating, that we are currently inside drawTextEx. This marker is not threadsafe, so the
    395. * plugin likely won't work with other plugins, that are asynchronously drawing text.
    396. */
    397. IAVRA.Window_Base_drawTextEx = Window_Base.prototype.drawTextEx;
    398. Window_Base.prototype.drawTextEx = function(text, x, y) {
    399.     IvCoreinDrawTextEx = true;
    400.     IAVRA.result = IAVRA.Window_Base_drawTextEx.call(this, text, x, y);
    401.     IvCoreinDrawTextEx = false;
    402.     return IAVRA.result;
    403. };
    404. /**
    405. * Replaces all escape codes, before AND after converting escape characters. We have to do this twice, because
    406. * otherwise we would miss escape codes in character names, that have been added via escape characters.
    407. */
    408. IAVRA.Window_Base_convertEscapeCharacters = Window_Base.prototype.convertEscapeCharacters;
    409. Window_Base.prototype.convertEscapeCharacters = function(text) {
    410.     return IvCoreReplace(IAVRA.Window_Base_convertEscapeCharacters.call(this, IvCoreReplace(text)));
    411. };
    412. //=============================================================================
    413. // Bitmap(RPG CORE)
    414. //=============================================================================
    415. /**
    416. * When drawing text, replace escape codes unless we are currently inside drawTextEx. Without this check, we
    417. * would effectively call our replace method for every single character of the text given to drawTextEx.
    418. */
    419. IAVRA.Bitmap_drawText = Bitmap.prototype.drawText;
    420. Bitmap.prototype.drawText = function(text, x, y, maxWidth, lineHeight, align) {
    421.     IAVRA.Bitmap_drawText.call(this, IvCoreinDrawTextEx ? text : IvCoreReplace(text), x, y, maxWidth, lineHeight, align);
    422. };
    423. /**
    424. * Measuring text is done, before drawing it, so escape codes won't be resolved, yet.
    425. */
    426. IAVRA.Bitmap_measureTextWidth = Bitmap.prototype.measureTextWidth;
    427. Bitmap.prototype.measureTextWidth = function(text) {
    428.     return IAVRA.Bitmap_measureTextWidth.call(this, IvCoreReplace(text));
    429. };
    430. //=============================================================================
    431. // String(RPG CORE)
    432. //=============================================================================
    433. /**
    434. * Needs to be aliased, so the state and skill messages (among others) works correctly.
    435. */
    436. IAVRA.String_format = String.prototype.format;
    437. String.prototype.format = function() {
    438.     return IAVRA.String_format.apply(IvCoreReplace(this), arguments);
    439. };
    440. // A FIX FOR WINDOW_NAME EDIT MADE BY IAVRA FOR SOMEONE IN THE THREAD.
    441. IAVRA.Window_NameEdit_initialize = Window_NameEdit.prototype.initialize;
    442. Window_NameEdit.prototype.initialize = function(actor, maxLength) {
    443.     actor._name = IAVRA.MasterLocalization.I18N.localize(actor._name);
    444.     IAVRA.Window_NameEdit_initialize.call(this, actor, maxLength);
    445. };
    446. //=============================================================================
    447. // LOCALIZATION MENU
    448. //=============================================================================
    449. /**
    450. * Returns the previous language in the list or the last language, if the current one is already the first.
    451. */
    452. // Eliaquim: I'V changed the behaviour of this to fix a bug.
    453. function IvCorePrevLanguage(language) {
    454.     var languages = IAVRA.MasterLocalization.I18N.languages();
    455.     var index = languages.indexOf(language) - 1;
    456.     return languages[index < 0 ? languages.length - 1 : index];
    457. };
    458. /**
    459. * Returns the next language in the list or the first language, of the current one is already the last.
    460. */
    461. // Eliaquim: I'V changed the behaviour of this to fix a bug.
    462. function IvCoreNextLanguage(language) {
    463.     var languages = IAVRA.MasterLocalization.I18N.languages();
    464.     var index = languages.indexOf(language) + 1;
    465.     return languages[index >= languages.length ? 0 : index];
    466. };
    467. /**
    468. * Applies the given language and returns it or the default fallback, if the given value was invalid. We don't
    469. * directly change the language, after it was selected in the options menu, because otherwise you would see a
    470. * mixed of different languages, while changing options.
    471. */
    472. function IvCoreApplyLanguage(language) {
    473.     IAVRA.MasterLocalization.I18N.language = language;
    474.     return IAVRA.MasterLocalization.I18N.language;
    475. };
    476. //=============================================================================
    477. // Window_Options
    478. //=============================================================================
    479. // Eliaquim: I'v add this to fix a bug.
    480. IAVRA.Window_Options_initialize = Window_Options.prototype.initialize;
    481. Window_Options.prototype.initialize = function() {
    482.     ConfigManager.language = IAVRA.MasterLocalization.I18N.language;
    483.     IAVRA.Window_Options_initialize.call(this);
    484. };
    485. IAVRA.Window_Options_makeCommandList = Window_Options.prototype.makeCommandList;
    486. Window_Options.prototype.makeCommandList = function() {
    487.     IAVRA.Window_Options_makeCommandList.call(this);
    488.     this.addCommand(IAVRA.MasterLocalization.Param.IvCoreLabelOption, 'language');
    489. };
    490. IAVRA.Window_Options_statusText = Window_Options.prototype.statusText;
    491. Window_Options.prototype.statusText = function(index) {
    492.     var symbol = this.commandSymbol(index);
    493.     var value = this.getConfigValue(symbol);
    494.     return symbol === 'language' ? IAVRA.MasterLocalization.Param.IvCoreLabelLanguages[value] : IAVRA.Window_Options_statusText.call(this, index);
    495. };
    496. IAVRA.Window_Options_processOk = Window_Options.prototype.processOk;
    497. Window_Options.prototype.processOk = function() {
    498.     var symbol = this.commandSymbol(this.index());
    499.     var value = this.getConfigValue(symbol);
    500.     if(symbol === 'language') {
    501.         return this.changeValue(symbol, IvCoreNextLanguage(value));
    502.     }
    503.     IAVRA.Window_Options_processOk.call(this);
    504. };
    505. IAVRA.Window_Options_cursorLeft = Window_Options.prototype.cursorLeft;
    506. Window_Options.prototype.cursorLeft = function(wrap) {
    507.     var symbol = this.commandSymbol(this.index());
    508.     var value = this.getConfigValue(symbol);
    509.     if(symbol === 'language') {
    510.         return this.changeValue(symbol, IvCorePrevLanguage(value));
    511.     }
    512.     IAVRA.Window_Options_cursorLeft.call(this, wrap);
    513. };
    514. IAVRA.Window_Options_cursorRight = Window_Options.prototype.cursorRight;
    515. Window_Options.prototype.cursorRight = function(wrap) {
    516.     var symbol = this.commandSymbol(this.index());
    517.     var value = this.getConfigValue(symbol);
    518.     if(symbol === 'language') {
    519.         return this.changeValue(symbol, IvCoreNextLanguage(value));
    520.     }
    521.     IAVRA.Window_Options_cursorRight.call(this, wrap);
    522. };
    523. //=============================================================================
    524. // ConfigManager
    525. //=============================================================================
    526. /**
    527. * The current language. Automatically gets kept in sync with the core plugin, whenever the current language
    528. * is written to or read from the config savefile.
    529. */
    530. var IvCoreLanguage;
    531. /**
    532. * Store the currently selected language in the config savefile, so it's persisted between games. Before
    533. * saving the language, it gets applied, so we can correctly fallback to the default language, if needed.
    534. */
    535. IAVRA.ConfigManager_makeData = ConfigManager.makeData;
    536. ConfigManager.makeData = function() {
    537.     var config = IAVRA.ConfigManager_makeData.call(this);
    538.     config.language = this.language = IvCoreApplyLanguage(this.language);
    539.     return config;
    540. };
    541. /**
    542. * Load the current language from the config savefile. Also, apply it, so we can display the correct language
    543. * and fallback to the default language, if the savefile entry doesn't exist or is invalid.
    544. */
    545. IAVRA.ConfigManager_applyData = ConfigManager.applyData;
    546. ConfigManager.applyData = function(config) {
    547.     IAVRA.ConfigManager_applyData.call(this, config);
    548.     this.language = IvCoreApplyLanguage(config.language);
    549. };
    550. /**
    551. * Read and set the current language. Language is managed locally, because otherwise we would experience some
    552. * strange sideffects in the options menu.
    553. */
    554. Object.defineProperty(IAVRA, 'language', {
    555.     get: function() {
    556.         return IvCoreLanguage;
    557.     },
    558.     set: function(value) {
    559.         IvCoreLanguage = value;
    560.     }
    561. });
    562. IAVRA.MasterLocalization.Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    563. Game_Interpreter.prototype.pluginCommand = function (command, args) {
    564.     IAVRA.MasterLocalization.Game_Interpreter_pluginCommand.call(this, command, args);
    565.     const cmd = command.toUpperCase();
    566.     if(cmd === "SET_LANG"){
    567.         IAVRA.MasterLocalization.I18N.language = args[0];
    568.     }
    569. };
    复制代码




    Update Log
    Version 1.0 - 04/10/2020
    - Released!


    本贴来自国际rpgmaker官方论坛作者:Eliaquim处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/iavra_masterlocalization.120038/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-1 10:42 , Processed in 0.094436 second(s), 55 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表