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

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

问题描述

我的应用程序支持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"= "Congratulations! %@ won the match & became professional player";

2)"WINNER_ALERT_SEMI_PROFESSIONAL"= "Congratulations! %@ won the match & became semi-professional player";

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

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