ios 应用名本地化_ios应用程序的本地化

ios 应用名本地化

NSLocalizedString (NSLocalizedString)

I am sure most of us have used or implemented custom wrapper over NSLocalizedString to access to localized strings in their code.

我确信我们大多数人都在NSLocalizedString上使用或实现了自定义包装,以访问其代码中的本地化字符串。

NSLocalizedString("key_name", comment: "comment")

Most of us centralized the NSLocalizedString keys in single file as it is not good idea spread raw strings across app and there are high chances of error, But that still doesn’t solve our problem to write the above function again and again every time we set the strings to our UI components.

我们大多数人将NSLocalizedString 密钥集中在单个文件中,因为这不是个好主意,可以在应用程序中分布原始字符串,并且出错的可能性很高,但这仍然不能解决每次设置一次又一次编写上述函数的问题。我们的UI组件的字符串。

Also imagine if you are working across the Teams Example: (Content, Tech) where Content team share localization files to Tech team.

还要想象一下,如果您跨团队工作,例如:(内容,技术),其中内容团队将本地化文件共享给技术团队。

So Definitely we need some developer friendly syntax to ease the process of exporting the localization code and also accessing the localized strings in our code.

因此,我们绝对需要一些开发人员友好的语法来简化导出本地化代码以及访问代码中本地化字符串的过程。

开始吧 (Let’s Start)

I am not covering the part about how to add multiple Localization in your app, It’s pretty straight forward from the below image, Click on +(plus) icon and add the localization you want and it will create all resource files in the project.

我没有涉及如何在您的应用程序中添加多个本地化的部分,这很简单,从下图开始,单击+(加号)图标并添加所需的本地化,它将在项目中创建所有资源文件。

Image for post
Screenshot from sample app supporting Localization
支持本地化的示例应用程序的屏幕截图

Now, We will first create Localizable propertyWrapper to handle the logic of getting the localized string from the particular key.

现在,我们将首先创建Localizable propertyWrapper,以处理从特定键获取本地化字符串的逻辑。

Then we will create Strings enum where we will store all localized keys. You can also distribute it across many features in your app. But for simplicity we will store all in single enum.

然后,我们将创建Strings枚举,其中将存储所有本地化的键。 您还可以在应用程序的许多功能中分发它。 但是为了简单起见,我们将全部存储在单个枚举中。

enum Strings {
@Localizable static var featureOneTitle = "featureOneTitle"
@Localizable static var featureTwoTitle = "featureTwoTitle"
}

Now with single line of code we can access our localized string and set to any UI Components or Variables, For Example

现在,只需一行代码,我们就可以访问本地化的字符串并设置为任何UI组件或变量, 例如

label.text = Strings.featureOneTitle

自动化Enum(Strings)代码生成 (Automate the Enum(Strings) code generation)

Okay now Let’s automate this, We don’t want to generate Strings keys every time when changes are made by Content team to improve the copy or when new strings are added for any feature.

好的,现在让我们自动化。我们不希望每次Content团队进行更改以改善副本时或为任何功能添加新字符串时都生成Strings键。

In this example, Consider Content team are using Google sheet where all keys added, Like below screenshot

在此示例中,考虑内容团队正在使用Google表,其中添加了所有键,如下面的屏幕截图所示

Image for post
Screenshot of Sample Google Sheet example
示例Google表格示例的屏幕截图

Now we will create custom script to generate our code, I took this inspiration from this git repo. I tweak the script for my own need to create code for my case, You can check the script from my git repo link and use it.

现在,我们将创建自定义脚本来生成我们的代码,我从git repo中获得了灵感。 我根据需要为自己的案例创建代码来调整脚本,您可以从git repo 链接中检查脚本并使用它。

The script will help you with generating all code required for Localization. Like for our current example it will give you the enum and all Localizable strings required for your project.

该脚本将帮助您生成本地化所需的所有代码。 像我们当前的示例一样,它将为您提供枚举和项目所需的所有Localizable字符串。

  • Strings Enum

    字符串枚举

enum Strings {
@Localizable static var home_title = "home_title"
}
  • Localizable.strings (English)

    Localizable.strings(英语)

“home_title” = “Home”
  • Localizable.strings (Thai)

    Localizable.strings(泰语)

“home_title” = “หน้าหลัก”

In this way we automate the code generation for Localization and build a custom Localization wrapper to use across our app.

通过这种方式,我们可以自动为本地化生成代码,并构建自定义的本地化包装器,以在我们的应用程序中使用。

谢谢😊 (Thank You 😊)

I hope this article helps you in implementing Localization in your app, Do share your valuable feedback.

希望本文能帮助您在应用程序中实现本地化,并分享宝贵的反馈意见。

翻译自: https://medium.com/flawless-app-stories/localization-for-ios-app-fd77be0045de

ios 应用名本地化

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值