|
Post by account_disabled on Jan 29, 2024 7:21:42 GMT
推特 Facebook 领英 电子邮件 复制链接 将 Sprout Social 这样的动态应用程序本地化为多种语言是一项复杂的任务。翻译应用程序中出现的文本只是故事的一半。它还涉及以一种可以轻松提取和替换翻译文本的方式开发我们的应用程序。在 Sprout,我们依靠第三方供应商进行翻译。但我们仍然需要工具来提取、捆绑并向这些供应商提交翻译请求,然后向最终用户提供和呈现翻译。 多年来,Sprout 工程团队一直采用自定义本地化解决方案,因为开源解决方案仍处于成熟阶段。它使我们能够以我们支持的语言容纳我们最大的客户,但缺乏一些有用的功能。在本文中,我将概述我们的新本地化系统、它如何处理最复杂的本地化场景,以及我们如何在整个网络工程组织中逐步引入这些更改。 我们的旧系统 要了解我们的新本地化系统,您首先需要了解我们的旧系统如何工作以及我们可以改进的领域。 消息语法 应用程序本地化的工作原理是将最终用户可见的文本抽象为字符串单元(称为消息)。 这些消息被提取并提交给翻译人员。通过抽象这些字符串,我们可以根据最终用户的 WhatsApp 数据 首选语言轻松地交换它们。 这些消息可以是简单的静态字符串,如“Hello, world”,也可以具有占位符,如“Hello, {name}”或富文本格式,如“Hello, <bold>world</bold>”。由于这些功能需要序列化为字符串,因此您需要翻译器和应用程序代码都能理解的语法才能正确翻译和呈现文本。 我们的旧本地化系统难以使用的部分原因是我们编写了自己的语法并为所述语法维护了一个自制的“解析器”。这段代码的维护非常耗时,而且语法也非常少。我们需要额外的功能来帮助呈现更复杂的消息。 示例:在 Sprout 应用程序中,我们需要一种呈现“You have X posts”的方法,其中 X 是动态数值。 考虑复数情况,“You have 5 posts ”。考虑单一情况,“您有 1 个帖子”。考虑“0”的情况。考虑可能具有“1”情况语法的语言,例如中文和日语。考虑具有针对 X 是“大数”情况的语法的语言,例如阿拉伯语、波兰语和俄语。 留言管理 我们可以将消息发送给翻译人员并在我们的应用程序中交换。我们的应用程序需要一种存储这些消息并将其提供给最终用户的方法。 我们的旧系统将所有消息存储在 JSON 文件(我们称为“lang 文件”)中,这些文件是手动管理的。我们通过使用源 JavaScript 代码中的 ID 来引用这些文件中的消息。当用户需要西班牙语应用程序时,我们将提供西班牙语文件,然后 javascript 将使用 ID 呈现相应的西班牙语消息。 出于性能原因,我们尝试仅提供该页面上的用户消息,因此我们为应用程序的不同页面提供了单独的 lang 文件。这是一个有效的系统,但随着我们的团队和应用程序的扩展,这意味着开发人员需要更多的手动时间来创建和管理这些 ID 和 lang 文件。 之前用于手动管理 Sprout 代码库中的消息和翻译的 JavaScript 的屏幕截图。 要向应用程序添加新消息,开发人员必须手动将它们添加到正确的 lang 文件中,并使用唯一的 ID 来引用该消息。有时,我们会遇到 ID 冲突和 ID 拼写错误的问题,导致应用程序中缺少 lang。向 Web 应用程序添加文本感觉很乏味,有许多不直观的步骤。
|
|