localizedString(forRegionCode:) uses a language the app does not support
iPad Settings:
The language order is:
- French
- Chinese
and the region is set to germany.
The app supports:
- chinese
The pod supports:
- chinese
- french.
Now, in the pod, When I call NSLocalizedString
s like this:
NSLocalizedString("Search", tableName: nil, bundle: loginBundle, value: "", comment: "Search")
I get the translation in chinese (as expected).
However, when I call NSLocale.current.localizedString(forRegionCode:)
I get the country name in french instead of chinese. NSLocale.current.languageCode
is "zh"
and NSLocale.current.regionCode
is "DE"
How can I get the country name in the currently used language?
ios swift xcode locale
add a comment |
iPad Settings:
The language order is:
- French
- Chinese
and the region is set to germany.
The app supports:
- chinese
The pod supports:
- chinese
- french.
Now, in the pod, When I call NSLocalizedString
s like this:
NSLocalizedString("Search", tableName: nil, bundle: loginBundle, value: "", comment: "Search")
I get the translation in chinese (as expected).
However, when I call NSLocale.current.localizedString(forRegionCode:)
I get the country name in french instead of chinese. NSLocale.current.languageCode
is "zh"
and NSLocale.current.regionCode
is "DE"
How can I get the country name in the currently used language?
ios swift xcode locale
What'sLocale.current.identifier
?
– user28434
Nov 22 '18 at 12:33
@user28434Locale.current.identifier
iszh-Hans_DE
– Daniel
Nov 22 '18 at 13:48
Because I need the country name in my current language and not the language name, but I would guess it woult take the same language @PranavKasetti
– Daniel
Nov 22 '18 at 20:24
add a comment |
iPad Settings:
The language order is:
- French
- Chinese
and the region is set to germany.
The app supports:
- chinese
The pod supports:
- chinese
- french.
Now, in the pod, When I call NSLocalizedString
s like this:
NSLocalizedString("Search", tableName: nil, bundle: loginBundle, value: "", comment: "Search")
I get the translation in chinese (as expected).
However, when I call NSLocale.current.localizedString(forRegionCode:)
I get the country name in french instead of chinese. NSLocale.current.languageCode
is "zh"
and NSLocale.current.regionCode
is "DE"
How can I get the country name in the currently used language?
ios swift xcode locale
iPad Settings:
The language order is:
- French
- Chinese
and the region is set to germany.
The app supports:
- chinese
The pod supports:
- chinese
- french.
Now, in the pod, When I call NSLocalizedString
s like this:
NSLocalizedString("Search", tableName: nil, bundle: loginBundle, value: "", comment: "Search")
I get the translation in chinese (as expected).
However, when I call NSLocale.current.localizedString(forRegionCode:)
I get the country name in french instead of chinese. NSLocale.current.languageCode
is "zh"
and NSLocale.current.regionCode
is "DE"
How can I get the country name in the currently used language?
ios swift xcode locale
ios swift xcode locale
asked Nov 22 '18 at 11:51
DanielDaniel
12.5k557120
12.5k557120
What'sLocale.current.identifier
?
– user28434
Nov 22 '18 at 12:33
@user28434Locale.current.identifier
iszh-Hans_DE
– Daniel
Nov 22 '18 at 13:48
Because I need the country name in my current language and not the language name, but I would guess it woult take the same language @PranavKasetti
– Daniel
Nov 22 '18 at 20:24
add a comment |
What'sLocale.current.identifier
?
– user28434
Nov 22 '18 at 12:33
@user28434Locale.current.identifier
iszh-Hans_DE
– Daniel
Nov 22 '18 at 13:48
Because I need the country name in my current language and not the language name, but I would guess it woult take the same language @PranavKasetti
– Daniel
Nov 22 '18 at 20:24
What's
Locale.current.identifier
?– user28434
Nov 22 '18 at 12:33
What's
Locale.current.identifier
?– user28434
Nov 22 '18 at 12:33
@user28434
Locale.current.identifier
is zh-Hans_DE
– Daniel
Nov 22 '18 at 13:48
@user28434
Locale.current.identifier
is zh-Hans_DE
– Daniel
Nov 22 '18 at 13:48
Because I need the country name in my current language and not the language name, but I would guess it woult take the same language @PranavKasetti
– Daniel
Nov 22 '18 at 20:24
Because I need the country name in my current language and not the language name, but I would guess it woult take the same language @PranavKasetti
– Daniel
Nov 22 '18 at 20:24
add a comment |
1 Answer
1
active
oldest
votes
The language used in the app is device-specific first, and then app-specific. So, it uses the most preferred language on the device first, which is also available in the bundle. In particular you can test why the issue is happening by looking at Locale.preferredLanguages.first
.
See here. So, you can get what you're looking for with:
Locale(identifier: Bundle.main.preferredLocalizations[0]).localizedString(forRegionCode:)
To ensure you set the bundle’s preferred localisation to Chinese, you could also manually select the Locale using Locale(identifier: “zh”). But using the app bundle fixes the issue without hardcoding.
That’s actually the oposite as what I want
– Daniel
Nov 22 '18 at 22:37
Could you explain why? I thought the pods first preference language was Chinese.
– Pranav Kasetti
Nov 22 '18 at 22:42
The iPad is set to: French, Chinese. And I want it to show chinese, since the app does not support french
– Daniel
Nov 23 '18 at 7:16
but the pod's first language would be french, since it uses the order in settings. The pod's languages have no order
– Daniel
Nov 23 '18 at 7:25
Also, why would it work withLocale(identifier: loginBundle.preferredLocalizations[0])
with zh, when I am usingLocale.current
with zh and it doesn't?
– Daniel
Nov 23 '18 at 7:28
|
show 2 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430414%2flocalizedstringforregioncode-uses-a-language-the-app-does-not-support%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The language used in the app is device-specific first, and then app-specific. So, it uses the most preferred language on the device first, which is also available in the bundle. In particular you can test why the issue is happening by looking at Locale.preferredLanguages.first
.
See here. So, you can get what you're looking for with:
Locale(identifier: Bundle.main.preferredLocalizations[0]).localizedString(forRegionCode:)
To ensure you set the bundle’s preferred localisation to Chinese, you could also manually select the Locale using Locale(identifier: “zh”). But using the app bundle fixes the issue without hardcoding.
That’s actually the oposite as what I want
– Daniel
Nov 22 '18 at 22:37
Could you explain why? I thought the pods first preference language was Chinese.
– Pranav Kasetti
Nov 22 '18 at 22:42
The iPad is set to: French, Chinese. And I want it to show chinese, since the app does not support french
– Daniel
Nov 23 '18 at 7:16
but the pod's first language would be french, since it uses the order in settings. The pod's languages have no order
– Daniel
Nov 23 '18 at 7:25
Also, why would it work withLocale(identifier: loginBundle.preferredLocalizations[0])
with zh, when I am usingLocale.current
with zh and it doesn't?
– Daniel
Nov 23 '18 at 7:28
|
show 2 more comments
The language used in the app is device-specific first, and then app-specific. So, it uses the most preferred language on the device first, which is also available in the bundle. In particular you can test why the issue is happening by looking at Locale.preferredLanguages.first
.
See here. So, you can get what you're looking for with:
Locale(identifier: Bundle.main.preferredLocalizations[0]).localizedString(forRegionCode:)
To ensure you set the bundle’s preferred localisation to Chinese, you could also manually select the Locale using Locale(identifier: “zh”). But using the app bundle fixes the issue without hardcoding.
That’s actually the oposite as what I want
– Daniel
Nov 22 '18 at 22:37
Could you explain why? I thought the pods first preference language was Chinese.
– Pranav Kasetti
Nov 22 '18 at 22:42
The iPad is set to: French, Chinese. And I want it to show chinese, since the app does not support french
– Daniel
Nov 23 '18 at 7:16
but the pod's first language would be french, since it uses the order in settings. The pod's languages have no order
– Daniel
Nov 23 '18 at 7:25
Also, why would it work withLocale(identifier: loginBundle.preferredLocalizations[0])
with zh, when I am usingLocale.current
with zh and it doesn't?
– Daniel
Nov 23 '18 at 7:28
|
show 2 more comments
The language used in the app is device-specific first, and then app-specific. So, it uses the most preferred language on the device first, which is also available in the bundle. In particular you can test why the issue is happening by looking at Locale.preferredLanguages.first
.
See here. So, you can get what you're looking for with:
Locale(identifier: Bundle.main.preferredLocalizations[0]).localizedString(forRegionCode:)
To ensure you set the bundle’s preferred localisation to Chinese, you could also manually select the Locale using Locale(identifier: “zh”). But using the app bundle fixes the issue without hardcoding.
The language used in the app is device-specific first, and then app-specific. So, it uses the most preferred language on the device first, which is also available in the bundle. In particular you can test why the issue is happening by looking at Locale.preferredLanguages.first
.
See here. So, you can get what you're looking for with:
Locale(identifier: Bundle.main.preferredLocalizations[0]).localizedString(forRegionCode:)
To ensure you set the bundle’s preferred localisation to Chinese, you could also manually select the Locale using Locale(identifier: “zh”). But using the app bundle fixes the issue without hardcoding.
edited Nov 23 '18 at 7:34
answered Nov 22 '18 at 21:06
Pranav KasettiPranav Kasetti
1,9422823
1,9422823
That’s actually the oposite as what I want
– Daniel
Nov 22 '18 at 22:37
Could you explain why? I thought the pods first preference language was Chinese.
– Pranav Kasetti
Nov 22 '18 at 22:42
The iPad is set to: French, Chinese. And I want it to show chinese, since the app does not support french
– Daniel
Nov 23 '18 at 7:16
but the pod's first language would be french, since it uses the order in settings. The pod's languages have no order
– Daniel
Nov 23 '18 at 7:25
Also, why would it work withLocale(identifier: loginBundle.preferredLocalizations[0])
with zh, when I am usingLocale.current
with zh and it doesn't?
– Daniel
Nov 23 '18 at 7:28
|
show 2 more comments
That’s actually the oposite as what I want
– Daniel
Nov 22 '18 at 22:37
Could you explain why? I thought the pods first preference language was Chinese.
– Pranav Kasetti
Nov 22 '18 at 22:42
The iPad is set to: French, Chinese. And I want it to show chinese, since the app does not support french
– Daniel
Nov 23 '18 at 7:16
but the pod's first language would be french, since it uses the order in settings. The pod's languages have no order
– Daniel
Nov 23 '18 at 7:25
Also, why would it work withLocale(identifier: loginBundle.preferredLocalizations[0])
with zh, when I am usingLocale.current
with zh and it doesn't?
– Daniel
Nov 23 '18 at 7:28
That’s actually the oposite as what I want
– Daniel
Nov 22 '18 at 22:37
That’s actually the oposite as what I want
– Daniel
Nov 22 '18 at 22:37
Could you explain why? I thought the pods first preference language was Chinese.
– Pranav Kasetti
Nov 22 '18 at 22:42
Could you explain why? I thought the pods first preference language was Chinese.
– Pranav Kasetti
Nov 22 '18 at 22:42
The iPad is set to: French, Chinese. And I want it to show chinese, since the app does not support french
– Daniel
Nov 23 '18 at 7:16
The iPad is set to: French, Chinese. And I want it to show chinese, since the app does not support french
– Daniel
Nov 23 '18 at 7:16
but the pod's first language would be french, since it uses the order in settings. The pod's languages have no order
– Daniel
Nov 23 '18 at 7:25
but the pod's first language would be french, since it uses the order in settings. The pod's languages have no order
– Daniel
Nov 23 '18 at 7:25
Also, why would it work with
Locale(identifier: loginBundle.preferredLocalizations[0])
with zh, when I am using Locale.current
with zh and it doesn't?– Daniel
Nov 23 '18 at 7:28
Also, why would it work with
Locale(identifier: loginBundle.preferredLocalizations[0])
with zh, when I am using Locale.current
with zh and it doesn't?– Daniel
Nov 23 '18 at 7:28
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430414%2flocalizedstringforregioncode-uses-a-language-the-app-does-not-support%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What's
Locale.current.identifier
?– user28434
Nov 22 '18 at 12:33
@user28434
Locale.current.identifier
iszh-Hans_DE
– Daniel
Nov 22 '18 at 13:48
Because I need the country name in my current language and not the language name, but I would guess it woult take the same language @PranavKasetti
– Daniel
Nov 22 '18 at 20:24