在头文件中使用变量和常量定义进行本地化

发布于 2025-01-04 16:39:58 字数 300 浏览 1 评论 0原文

在这种情况下,当我有一个定义了一些参数的标头时,我该如何使用 NSLocalizedString ,比如:

#define appKey @"appKey1 is: %@"

我想我知道我的 Localized.strings 应该是这样的:

"blabla" = "appKey1 is: %@"

但是我该如何使用 NSLocalizedString 呢?我读到我需要使用 stringWithFormat,但不知道如何...

谢谢!

How do I use NSLocalizedString in this case when I have a header where I define a few parameters, say:

#define appKey @"appKey1 is: %@"

I think I know that my Localizable.strings should look like that:

"blabla" = "appKey1 is: %@"

but how do I use NSLocalizedString? I read that I need to use stringWithFormat, but not sure how...

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

ら栖息 2025-01-11 16:39:58

您可以将常量定义为:

#define appKey NSLocalizedString(@"appKey1 is: %@", @"appkey constant")

然后 genstrings 工具应该以通常的方式拾取它。

在字符串文件中,它会像这样出现:

/* appkey constant */
"appKey1 is: %@" = "appKey1 is: %@";

您只需翻译右侧即可。

You would define your constant as:

#define appKey NSLocalizedString(@"appKey1 is: %@", @"appkey constant")

Then it should get picked up by the genstrings tool in the usual way.

In the strings file it would then come out like this:

/* appkey constant */
"appKey1 is: %@" = "appKey1 is: %@";

And you would translate just the right hand side.

停顿的约定 2025-01-11 16:39:58

NSLocalizedStrings 中可以接受字符串文字。你需要做的是类似的事情

#define appKey NSLocalizedString(BlahBlah , comments);

"BlahBlah" = "appKey1 is: %@";

(确保在 Localized.strings 中以分号结束你的行,否则它最终会被损坏)。

String literals are acceptable in NSLocalizedStrings. What you need to do is something like

#define appKey NSLocalizedString(BlahBlah , comments);

"BlahBlah" = "appKey1 is: %@";

(Be sure to end your lines with a semi-colon in Localizable.strings, or it will end up being corrupted).

满意归宿 2025-01-11 16:39:58

这就是你通常会这样做的方式,

NSString * myString = [NSString stringWithFormat:@"appKey1 is: %@",yourAppKeyString];

因为你已经定义了它,所以你可以像这样使用它,

NSString * myString = [NSString stringWithFormat:appKey,yourAppKeyString];

无论哪种情况都会像这样填充你的 myString

yourAppKeyString = @"keyString";
myString = @"appKey1 is: keyString";

This is how you would do it normally,

NSString * myString = [NSString stringWithFormat:@"appKey1 is: %@",yourAppKeyString];

Since you have it defined you can use it like so

NSString * myString = [NSString stringWithFormat:appKey,yourAppKeyString];

Either case both would fill your myString like so

yourAppKeyString = @"keyString";
myString = @"appKey1 is: keyString";
凉栀 2025-01-11 16:39:58
NSString * myString = [NSString stringWithFormat: NSLocalizedString(@"appKey", @""),yourAppKeyString];
NSString * myString = [NSString stringWithFormat: NSLocalizedString(@"appKey", @""),yourAppKeyString];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文