LanguageAPI 是一个供插件开发者使用的工具,用于将插件国际化,使其能够轻松简单地翻译为任意语言。请注意:这 并非 一个翻译插件,而是协助人类翻译者和插件开发者的工具。这也 不是 一个独立运行的插件,它本身不会执行任何操作;它是供插件开发者集成到其项目中的工具。
如果您是插件开发者,并希望扩展用户群以支持其他语言,那么 LanguageAPI 提供了一种简单、易用且高效的方式来实现这一目标。您只需在项目中将 LanguageAPI jar 文件作为库包含进来,即可开始使用其功能。
如果您希望看到某个插件提供其他语言的版本,您可以联系该插件的作者,并礼貌地建议他们可以使用此 API,这将大大减轻他们的工作量。
基本思路是:所有需要显示给用户或从用户获取的字符串都从硬编码中分离出来,存放在 lang-???.yml 文件中(其中 ??? 为您的默认区域设置 ISO 代码)。默认的 lang-???.yml 文件会在测试期间自动生成,然后可以被翻译成其他语言。国际或多语言用户随后可以下载他们选择的 lang-???.yml 文件并与插件配合使用。当玩家设置其个人区域设置后,插件的消息将会被快速、高效地翻译为该语言,且无需重新编译。尽管国际或多语言用户也需要安装 LanguageAPI 才能使用您的插件,但为了能用母语使用您的插件,这是值得付出的小小代价。
您可能在想,既然我可以自己编写类似的功能并添加到我的插件中,为什么还要使用 API 插件呢?当然,您可以这样做,其他人也可以。但这会导致这样的情况:玩家需要在服务器上的每一个国际插件中单独设置他们的区域设置,而有些服务器拥有 20-30 个甚至更多的插件。这对他们来说非常令人烦恼,我相信您也会同意这一点。现在想象一下,如果许多插件都开始使用这个 API,而只有少数插件(包括您的)没有使用。玩家可以为整个服务器统一设置语言,却发现为了使用您的插件又不得不重新设置一次。
我还为 API 提供了一个包装类,它会检查是否安装了 LanguageAPI,如果没有,则使用默认翻译。这意味着您可以将 LanguageAPI 设为软依赖,您的本地语言用户甚至不需要安装 LanguageAPI 就能使用您的插件,从而避免给那些不需要翻译的用户带来不便。
- 简单易用
- 更新现有项目以使用 LanguageAPI 所需的代码改动极少
- 文档完善的 API 方法
- 支持多语言服务器
- 提供包装类,如果您的用户不需要翻译,则无需将 LanguageAPI 作为硬依赖
- 在 alpha 测试期间,根据您的代码自动为您的默认区域设置创建 lang-???.yml 文件
- 使用消息模板来处理需要填入动态数据的字符串
- 允许对这些消息模板进行完全自定义,以便翻译成其他语言
- 使用高效的字符串连接算法从模板编译显示字符串
- 强大的错误处理机制,当特定的 lang-???.yml 出现错误时,会回退使用默认语言
- 本插件不会神奇地将您的插件自动翻译成所有已知语言,仍需翻译者修改 lang-???.yml 文件以实现不同语言的翻译
- 它仅适用于专门为 LanguageAPI 编写的插件,您不能仅仅将其放入插件文件夹就期望它能翻译完全不相关的插件
- 它不会为您找出所有的输出字符串并将其放入 lang-???.yml 中,每次使用输出字符串时,您都必须调用语言库
- 它不会翻译玩家创建的游戏中聊天消息或书籍/告示牌中的文本
- 目前它不支持将 Bukkit 命令和帮助系统中的权限翻译成其他语言,不过未来可能会提供支持
如果您是从另一个插件跳转到此处的,您只需下载 LanguageAPI.jar 并将其放入您的 plugins 文件夹即可。您应该能够从引导您到此处的插件那里获取所需语言的 language.yml 文件。
从 Bukkit 下载 LanguageAPI.jar:
如果您希望在插件中包含语言支持,您需要下载 LanguageAPI.jar 并将其作为库包含到您的项目中。要开始使用它,您可以通过传入您的插件作为唯一参数来创建一个新的 Language 对象。随后可调用该 Language 对象以获取给定键的本地化字符串,同时它也定义了默认字符串模板。
从 Bukkit 下载 LanguageAPI.jar:
国际和多语言用户也需要一份 LanguageAPI,请引导他们访问此页面以从官方作者处获取最新版本。
有关开发者的详细帮助,请参阅 开发者 页面。
要将使用 LanguageAPI 的插件翻译成其他语言,您需要获取该插件默认的 language.yml 文件。他们应在其页面上提供给您,或在请求时提供。
该文件的格式实际上是 YAML 的简化版,不包含通常会使翻译变得繁琐的所有保留字符,因此您无需为此担心。其形式如下:
key: template text interspersed with {number}
您必须保持键名完全不变,不要进行翻译。这些键名不会显示在任何地方,它们仅用于插件确定使用哪个字符串模板。相反,您应该只翻译模板文本。
花括号中的数字指的是在插件运行时添加到字符串中的动态数据,例如:
player-slain: {0} was slain by {1}
其中 {0} 被玩家名称替换,{1} 被击杀玩家的实体或人物替换。
您可以随意重新排列这些占位符,甚至多次使用它们,例如:
player-slain: {1} has slain {0}. Bad luck for {0}!
但是,您不能创建新的占位符,只能使用现有的带花括号的数字。
帮助翻译 LanguageAPI 插件
如果您想帮助将 LanguageAPI 插件本身翻译成其他语言,请参阅 语言和翻译 页面。只要您的至少一个翻译正在使用中,您的 BukkitDev 个人资料将作为该项目的翻译者显示。
您可以在此处找到翻译者列表 这里。
此列表仅为方便起见提供,使用时风险自负。这不构成背书;我们无法验证翻译质量,也不为其真实性担保或调解纠纷。如果您使用此列表,您将承担由此产生的一切责任。
如果您是翻译者,并希望加入此列表,请通过私信联系我或留下评论,并说明您能够翻译的语言(以及 ISO 代码)。
此插件使用 Java 7
如果在安装此插件启动服务器时出现以下错误“Unsupported major.minor version 51.0”,这意味着您使用的是过时的 Java 版本。如果您不知道如何升级,请联系您的服务器托管提供商寻求帮助升级到 Java 7,或联系 Oracle 客户支持。Mac OS X 用户需要 JDK 7 而不是 JRE 7。
如果您希望为项目的持续开发、支持和维护做出贡献,请考虑加入我的 Patreon,并进行一次性或定期捐款。
如果您需要帮助,可以在下方留下评论,我会尽快回复您。您也可以使用以下链接加入我的 IRC 聊天室。请注意,我并不总是在键盘前!
LanguageAPI is a tool for plugin developers to internationalise their plugin to make it simple and easy to translate into any language. Please note: This is not a translation plugin, it is a tool to assist human translators and plugin developers. This is not a standalone plugin, it will not do anything by itself, it is a tool for plugin developers to include in their projects.
If you are a plugin developer, and you want to expand your user-base to include other languages, this LanguageAPI provides a simple, easy and effective means to do so. All you need to do is include the LanguageAPI jar as a library in your project and you can start to use its features.
If you would like to see another plugin in a different language, you could contact the author and politely suggest that they could use this API, as it would make the task a whole load easier for them.
The basic idea is that every string that is ever required from or displayed to a user is separated from the hard code in a lang-???.yml file (where ??? is your default locale ISO code). The default lang-???.yml file will be automatically generated during testing, and can then be translated into other languages. International or multi-language users can then download any lang-???.yml files of their choice to use with the plugin and after player's set their personal locale, messages from the plugin will be translated to that language, quickly, efficiently and without any recompilation necessary. Although international or multi-language users would also need to install the LanguageAPI with your plugin, it is a small price to pay to be able to use your plugin in their own language.
You may be asking, why use an API plugin when I could write something like this myself and add it to my plugin? Well, you certainly can do that, and so can everyone else. This will lead to situations where players need to set their locale for every single international plugin on a server, and some servers have 20-30 plugins or more. Very irritating for them, I am sure you'll agree. Now imagine a number of plugins start using the API and yours is one of the few that doesn't. Players can then set their languages for the whole server, and then find that they have to set it again just for your plugin.
I have also provided a wrapper class for the API, which checks to see if LanguageAPI is installed, and if it is not, uses the default translation. This means that you can soft-depend the LanguageAPI plugin and your local language users will not even need to install the LanguageAPI to use your plugin, which should avoid inconveniencing users who don't need any translations.
- Simple and easy to use
- Minimal code changes needed to update an existing project to use LanguageAPI
- Well-documented API methods
- Supports multi-language servers
- Provided a wrapper class so you don't need LanguageAPI as a hard dependency if your users don't require translations
- Automatically creates your default lang-???.yml file for your own locale from your own code during alpha testing
- Uses message templates to handle strings that need to have dynamic data entered into them
- Allows complete customisation of these message templates for translation into other languages
- Uses efficient string concatenation algorithms to compile the display string from templates
- Robust error-handling, reverts to using the default language when there are errors in a particular lang-???.yml
- This plugin does not magically translate your plugin into all known languages, it still requires translators to modify the lang-???.yml files into different languages
- It only works for plugins that are written specifically for the LanguageAPI, you cannot just drop it into your plugins folder and expect it to translate completely unrelated plugins
- It does not find all of your output strings for you and put them into the lang-???.yml, you have to call the language library every time you use an output string
- It does not translate in-game chat messages or text in books or signs created by players
- It currently does not provide support for translating the Bukkit help system for commands and permissions into other languages, however it may do so in the future
If you have been sent here from another plugin, all you need to do is download the LanguageAPI.jar and place it into your plugins folder. You should be able to obtain the language.yml file for your desired language from the plugin that directed you here.
Download the LanguageAPI.jar from Bukkit:
If you want to include language support in your plugin, you will need to download LanguageAPI.jar and include it as a library for your project. To start using it, you can create a new Language object using your plugin as the only parameter. This Language object can then be called to get the localised string for the given key, and also defines the default string template.
Download the LanguageAPI.jar from Bukkit:
International and multi-language users will also need a copy of the LanguageAPI, please direct them to this page so they can obtain the latest version from the official author.
For detailed help for developers, see the Developers page.
In order to translate a plugin that uses LanguageAPI to another language, you should obtain a copy of the default language.yml file for that plugin. They should provide this to you on their page, or on request.
The format for the file is actually a stripped down version of YAML, which does not contain all of the reserved characters which would normally make translations a pain, so you will not need to worry about this. It is in the following form:
key: template text interspersed with {number}
You must leave the keys exactly as they are, untranslated. These are not displayed anywhere, they are just used by the plugin to determine which string template to use. Instead, you should translate the template text only.
The curly braced numbers refer to dynamic data that is added to the strings while the plugin is running, e.g.
player-slain: {0} was slain by {1}
Where {0} is replaced by the player's name, and {1} is replaced by what or who has slain the player.
You can rearrange these as much as you want, even use multiples of them, e.g.
player-slain: {1} has slain {0}. Bad luck for {0}!
However, you cannot create new ones, only use existing braced numbers.
Help translate the LanguageAPI plugin
If you would like to help translate the LanguageAPI plugin itself into other languages, please see the Languages and Translation page. While at least one of your translations is currently in use, your BukkitDev profile will be displayed as a Translator for the project.
You can find a list of Translators here.
This list is provided for your convenience only and should be used at your own risk. This should not be considered an endorsement; we cannot verify the quality of translations nor do we vouch for their authenticity or mediate disputes. If you use this list, you take full responsibility for anything that may result from its use.
If you are a translator, and would like to be added to this list, please contact me via private message or leave a comment, and state which languages (and ISO codes) you are able to translate to and from.
This plugin uses Java 7
If you get the followed error on starting up the server with this plugin installed "Unsupported major.minor version 51.0". This means you are using an out of date version of Java. If you don't know how to upgrade, please contact your server hosting provider and ask them for help in upgrading to Java 7, or contact Oracle customer support. Mac OS X users require JDK 7 instead of JRE 7.
If you'd like to contribute towards the continued development, support and maintenance of this project, please consider joining me on Patreon, and making a one-time or recurring pledge.
If you need help you can leave a comment below and I will get back to you as soon as I can. You can also join my IRC chatroom using the following link. Please note, I am not always at my keyboard!
评论 0
登录后参与评分
还没有评论,来抢沙发吧