I need to localize my iOS application, from EN (English) to FR (Francais). the problem - most of FR strings are much longer than EN strings, so if I use the same UI, it does not look well with FR strings
When localizing android application, I used different resource files for each language, with smaller font, larger height, etc. ...
What is equivalent iOS solution for longer strings in different language?
for changing the font size, I can use this solution: - Swift3 different font in the All of the UIView with Localization each
Is there a simpler solution, in which I can see at design time how the screen is displayed?
You can fit texts into your views for all length using Auto Layout regardless of Font, Language, Orientation, DeviceSize etc.
There is a sample blog post for some tips for that:
Tips for using Auto Layout when localizing apps
Remove all fixed-width constraints. If the German text is 30% longer,
and you don’t provide room for it in your UI, this will at least let
iOS change the font size to accommodate. Otherwise, your localized
text will get cropped.
Text fields should fit to contents. Select Editor > Size To Fit
Content so that text fields and labels resize automatically for
longer or shorter text.
Pin views to adjacent views. This way, when one view resizes to fit
your localized text, the other views will too. Otherwise, views may
overlap in some languages
No minimums or maximums. Allow each content view to adjust in size as the language changes.
Use leading and trailing attributes instead of left and right. This
tip will make right-to-left languages (Arabic, Hebrew) flow properly.
You can also have look at Introduction to Auto Layout
You can use the following code snippet to determine the language setting of a device:
Locale.current.languageCode
And than you can change/set the font size accordingly
Related
Using autolayout to have a multiline UILabel auto size the text to fit does not work for single words.
Here is how storyboard is set up:
Here's the problem.
This does not display properly:
But this does:
I have adjusted every setting in the storyboard. I have changed all of the Line Break settings (wrap, truncate, etc), I have adjusted # of lines, I have made text plain vs attributed, I've changed font sizing and scaling, everything. What am I missing? Why does "California" get cut off instead of shrinking to fit? I've seen many other posts on SO and haven't yet found a solution (which needs to be compatible back to iOS 9)
Your label is being filled both horizontally and vertically until it runs out of space, then it starts shrinking the text to fit. In the one word example it breaks the word into two lines because there is vertical room.
Do you know in advance or can you calculate in the app when you have only one word in this label? If so you can change the number of lines to 1 instead of 0 so the app will keep the contents on one line and shrink this word.
Is there anything available in Xcode that allows for changing sizes(such as labels) for different languages? All I can find are mentions of using auto-layout to account for this but there are some areas where I have to change the label size. I could make an outlet for each label, detect the locale, and then change them that way but I was hoping for a cleaner solution.
The clean method is indeed auto layout, which can take the size of the text in a label into account. If that isn't good enough, then don't try looking at the locale, but look at the size of the text in the UILabel, measure it, and change things accordingly if needed.
I have an iOS Application that supports different languages, which uses LTR Storyboard and RTL Storyboard, and reads from Plists. When I run the app on my Device with English iOS Version, everything looks perfect when switching between the languages. But when I change the iPhone OS Language to RTL languages. The UI is messed up.
This happens especially when I enable Localizations to change the app name on home screen.
Any idea why does that happen?
The whole menu is messed up for example, it's to the left side while it should be to the right side, and the menu items icons must be to the left and the labels to the right.
RTL Language on LTR iOS Language Device i.e English
RTL Language on RTL iOS Language Device
This is because you are use leading and trailing constraint.
In a LTR environment leading means left while in an RTL environment, leading means right.
This is Apple way of helpings us to deal with RTL/LTR easily :[ in your case, not so much...
To disable this behaviour, change the semantic attribute of your views.
Semantic Content
If you lay out your views using leading and trailing constraints, the
views automatically flip positions when switching between
left-to-right languages (like English) and right-to-left languages
(like Arabic). However, some interface elements should not change
their position based on the reading direction. For example, buttons
that are based on physical directions (up, down, left, and right)
should always stay in the same relative orientation.
The view’s semanticContentAttribute property determines whether the
view’s content should flip when switching between left-to-right and
right-to-left languages.
In interface builder, set the Semantic option in the Attribute
inspector. If the value is Unspecified, the view’s content flips with
the reading direction. If it is set to Spatial, Playback, or Force
Left-to-Right, the content is always laid out with the leading edges
to the left and trailing edges to the right. Force Right-to-Left
always lays out the content with the leading edges to the right and
the trailing edges to the left.
Assuming that you are already using Auto Layout,
Make sure you have done the following
Remove fixed width constraints. Allow views that display localized text to resize. If you use fixed width constraints, localized text may appear cropped in some languages.
Use intrinsic content sizes. The default behavior for text fields and labels is to resize automatically. If a view is not adjusting to the size of localized text, select the view and choose Editor > Size To Fit Content.
Use leading and trailing attributes. When adding constraints, use the attributes leading and trailing for horizontal constraints. For left-to-right languages, such as English, the attributes leading and trailing are equivalent to left and right. For right-to-left language, such as Hebrew or Arabic, leading and trailing are equivalent to right and left. The leading and trailing attributes are the default values for horizontal constraints.
Pin views to adjacent views. Pinning causes a domino effect. When one view resizes to fit localized text, other views do the same. Otherwise, views may overlap in some languages.
Constantly test your layout changes. Test your app using different language settings, as described in Testing Your Internationalized App.
Don’t set the minimum size or maximum size of a window. Let the window and its content view adjust to the size of the containing views, which may change when the language changes.
See more
Probably a matters of constraints. In the storyboard, you can use the preview editor to get a .. well.. preview, of your UI in diffrent device size in different language.
If the text of a label in a universal storyboard is too long to fit some resolutions, how do I accommodate it?
Storyboard View
iPhone 6 Emulator
I'm not sure if there is a proper way to go about this according to the guidelines, but I would assume I would either text wrap onto multiple lines or adjust the font size automatically.
Here is a simple gif, which can help you to understand it better.
You can do either. First set the constraints so that the UILabel does not go past the edge of the screen. Then you have two options. Either set the minimum font size of set the number of lines to 0 (or both).
All of these settings can be set in storyboard.
Edit to following your comment
Constraints are usually set in the storyboard and dictate how a view is drawn based on the device you are using. It's a large and critical subject and Ray Wenderlich has a very good two part tutorial on it.
I have localized my application in arabic. While in arabic culture, I need to mirror my views using constraints like trailing and leading. what are the best practices to have a flipped view?
It may be interesting to note that when set to Arabic, its culture is set as #"ar-AE". I guess flipping the view doesn't work with the #"ar-AE" locale, although I'm unsure whether that's a bug, or if some arabic countries write LTR, thus making sense not to systematically flip the view.
Long story short what constraint settings are required to actually convert view into "Arabic" and properly flip a view?
Yes, using Leading and Trailing constraints is in theory all you should have to do.
The language variant should be independent of the appended region, and fall back to the generic language for layout information. If you are seeing LTR views in ar but not ar-AE, you should file a bug at bugreport.apple.com.