iOS - APNS 如何在有效载荷中使用 loc_key [英] iOS - APNS how to use loc_key in payload

查看:18
本文介绍了iOS - APNS 如何在有效载荷中使用 loc_key的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在让 APNS 向设备发送消息之前,我有一个消息字符串要本地化.我希望我能看到 json 负载本身,让我了解结构,而不是设备为我解析它.但无论如何,我如何使用 loc_key 和 loc_args 参数?从我发现的文档中:

I have a message string i want to localize before i let APNS send a message to devices. I wish i could see the json payload itself to make me understand the structure instead of the device parsing it out for me. but anyway, how do i use the loc_key and loc_args argument ? from the docs i found:

锁定键细绳当前本地化的 Localizable.strings 文件中警报消息字符串的键(由用户的语言首选项设置).可以使用 %@ 和 %n$@ 说明符格式化键字符串,以采用 loc-args 数组中指定的变量.有关详细信息,请参阅本地化格式化字符串.

loc-key string A key to an alert-message string in a Localizable.strings file for the current localization (which is set by the user’s language preference). The key string can be formatted with %@ and %n$@ specifiers to take the variables specified in the loc-args array. See Localized Formatted Strings for more information.

loc-args 字符串数组 变量字符串值出现在loc-key 中的格式说明符.请参阅本地化格式化字符串更多信息.

loc-args array of strings Variable string values to appear in place of the format specifiers in loc-key. See Localized Formatted Strings for more information.

官方文档是这里

我需要一个具体的例子来说明如何本地化一个字符串以及什么是 loc_args ?

I need a concrete example of how to localize a string and what is loc_args ?

我只是在这里猜测,但如果我有一个像这样本地化的字符串:mystring="很酷的本地化消息"那么 loc_key 将是mystring",对吗?

I am just guessing here, but if i have a string localized like this: mystring="cool localized message" then the loc_key will be "mystring", is that right ?

推荐答案

loc-key 是一个字符串,需要匹配应用程序包内 Localizable.strings 文件中的键.例如,如果 loc-key 是my-push.hello-world"并且您的 Localizable.strings 文件中有以下行:

loc-key is a string that needs to match a key in your Localizable.strings file inside the app bundle. For example if the loc-key is "my-push.hello-world" and you have the following line in your Localizable.strings file:

"my-push.hello-world" = "Hello, World!";

向用户显示的推送消息将显示为Hello, World".

the push message displayed to the user would read "Hello, World".

log-args 是将在消息中替换的字符串,就像你在 [NSString stringWithFormat:@"blabla %@"];

log-args are strings that will be replaced in the message, like your have it in [NSString stringWithFormat:@"blabla %@"];

苹果的例子是这样的:

推送通知负载:

"alert" : { 
    "loc-key" : "GAME_PLAY_REQUEST_FORMAT",
    "loc-args" : [ "Jenna", "Frank"]
}

Localizable.strings 内容:

Localizable.strings content:

"GAME_PLAY_REQUEST_FORMAT" = "%@ and %@ have invited you to play Monopoly";

这篇关于iOS - APNS 如何在有效载荷中使用 loc_key的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆