How to switch language for one element of iOS-App? - ios

My question:
How to switch language for one element of iOS-App ?
I have app with different languages locale there
function of switch locale (language) work fine.
but I can't to understand how to make function for my special element (button) that switched only part of my app to another language.
So I can't to find any information about right solution.
Any one please help

I don't think UIKit provides such a fine grained localization support (i.e., language per view). The current locale is an application wide setting, made available by Locale.current.
You may need to track such settings yourself and configure the desired views accordingly.

Related

Does Xcode have predefined localized words/phrases I can use in app?

Does Xcode or Swift have a list of predefined localized words (e.g. "Delete", "Edit" etc.) that I can use in my app and to be sure that it localized properly?
If you have a Navigationview and you use a Navigationlink, you will see, that the back button will be localized automatically (at lest for german in my app). So all buttons that get generated for you, could be localized for some languages.
But as far as I know, there is no set of predefined localizations you could access to use. Though it is very easy in SwiftUI to make localizations, just have a look at:
https://phrase.com/blog/posts/swiftui-tutorial-localization/
If you have a string file with your localizations you can use the definitions of those strings directly in the text parameters of the SwiftUI Views and they will automatically be changed with the localized version, no need to even cast the identifier of the string in the strings file to a LocalizedStringKey.
Seriously, if you were to rely on some automatic translation for your UI, then I can promise you that people will complain, because most will find an automatic translation into their own language harder to read than good English.

IOS apps that will support both RTL and LTR in one application which can be changed dynamically

I am confused to design the application in RTL as well as LTR
1: I have created two story board for Arabic and normal home for all languages except Arabic.
2: I have tried to change the app language in application but it will require restart the application so how can i restart ?? .
3: ios9 provide new feature but at time only one language we have to select from project->edit scheme-> language but I need two language support English as well as Arabic at one application which can be change dynamically.
Please give me your suggestions. Thanks.
You can save the user language preference. Acc. to the language specified you can display the data in the specified language. You don't need to create separate storyboards for each languages. Just dynamically retrieve the language specified and display the data accordingly.

Having a language select option in an app using Swift

I have Googled this for hours but could find no advice for the following problem (using Swift).
I have seen in many apps an option to select the language from inside the app like this:
(source: unity3d.com)
I would like to achieve something similar, but am having trouble implementing it. I have localized my app and have my Localizable.strings files all set up. I'd imagine it has something to do with storing the language selected in NSUserDefaults, but how can I make the app use the appropriate Localizable.strings file once a language has been chosen? Or is that the wrong way to approach it?
How have others successfully implemented this feature in Swift?
I've already faced this issue on one of my project and found one solution :
When the user select a language from a list, post a NSNotification. All your UIViewController subclass must register to this notification and change the labels value according to the new language selected.
You can use the localized strings in order to set the labels, but NSLocalizedString(...) shouldn't be called since it's relying on the device language which is different from the application language.
You can find my implementation of a custom localisator on Github, available both on Swift and objective-C.

How to override current language used inside an app

I've found testing localizations to be a slight pain since I have to go and change the device's language in order for the app to change.
How can I make my app "think" I changed my default language? I could then link that to a button or popover, but the actual changing of the language is the tricky part.
You can test the with any of the supported languages or regions by settings then in the option of the run target.
This fully described in Internationalization and Localization Guide

How to detect localization on basis of Settings.bundle selection (Story board app)

I am working on an iOS app which is having combination of story board and Localization (based on two languages, i.e. English and Slovenian).
I have created the two folder (en.lproj and sl.lproj) for both the languages. Both are having InfoPlist.string and MainStoryboard.storyboard files. I also need to implement language selection through Settings.bundle.
I have created Settings.bundle and able to select language from my app settings inside device setting option.
Now my trouble points are :
How can I get the selected value on AppliactionDidBecomeActive which is being recently set by user from setting?
After getting this value, how can I load selected language folder (say en.lproj etc)
How can I get the Slovenian language option in device language settings?
My application will work on either by selecting device language or on selecting my NSBundle setting.
Please provide me suggestion on the basis of some code part or help me on any other way.
Thank you and waiting for good response.
1.
NSString * lan = [[NSLocale preferredLanguages] objectAtIndex:0];
NSLog(#"language :%#",lan);
Not sure I understand your question (should be automatic).
If Slovenian is not yet supported by iOs, there is no way you'll see in the language settings.
In short you'll probably need to add a language selection option in your app. and change the language manually (including for the storyboard) using the NSLocalizedStringFromTable function.
Hope this help

Resources