在 loc-args 中为 iOS 推送通知发送本地化的字符串键 [英] Send localized string key in loc-args for iOS Push notifications

查看:16
本文介绍了在 loc-args 中为 iOS 推送通知发送本地化的字符串键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序支持 4 种语言 &推送通知.当我向 APNS 发送推送通知时,我正在发送 loc_key &loc-args.现在我需要在 loc-args 数组中发送本地化的字符串,以便我可以在应用程序收到推送通知时在 iOS 应用程序端翻译这些字符串.

My application supports 4 languages & push notifications. When I send push notification to APNS , I am sending loc_key & loc-args. Now I need to send localized strings in loc-args array so that I can translate those on iOS app side when app receives the push notification.

但是当我在 loc-args 中发送本地化的字符串时,它没有在通知中心显示翻译的字符串,而是按原样显示本地化的密钥.

But when I send localized strings in loc-args , instead of showing translated string in notification center , it just showed localized key as it is.

我的字符串文件包含以下 2 条消息:

My string file contains below 2 messages:

"WINNER_ALERT"= "Congratulations! %@ won the match & became %@ player";
"ROLE_PROFESSIONAL_LOCALIZED_KEY" = "professional"

服务器发送以下有效负载

Server sends below payload

{
    aps =     {
        alert =         {
            "loc-args" =             (
                "John",
                "ROLE_PROFESSIONAL_LOCALIZED_KEY"
            );
            "loc-key" = "WINNER_ALERT";
        };
        badge = 1;
        sound = default;
    };
}

当我在 iOS 通知中心发送上述有效负载时,消息看起来像

When I send above payload then in iOS Notification Center , message look like

Congratulations! John won the match & became ROLE_PROFESSIONAL_LOCALIZED_KEY player

代替

Congratulations! JOHN won the match & became professional player

谁能告诉我是否可以在 loc-args 中发送本地化的字符串?如果是,我的有效载荷有什么问题?

Can anyone tell me whether it is possible to send localized strings in loc-args ? If yes, what's wrong in my payload ?

提前致谢

推荐答案

@Zak 的回答很有魅力.

@Zak answer's works like a charm.

此外,如果您需要professional 进行本地化,它应该是WINNER_ARERT 字符串的一部分.

Furthermore, if you need professional to be localised, it should be part of WINNER_ARERT string.

如果您需要为 professional 传递不同的字符串,您应该创建多个本地化的字符串.例如.:

If you need to pass different strings for professional, you should create several localised strings. E.G. :

1) "WINNER_ALERT_PROFESSIONAL"="恭喜!%@赢得比赛并成为职业选手";

2) "WINNER_ALERT_SEMI_PROFESSIONAL"="恭喜!%@赢得比赛并成为半职业选手";

这篇关于在 loc-args 中为 iOS 推送通知发送本地化的字符串键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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