Xcode 9 - 本地化问题警告故事板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45039846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode 9 - Localization Issue Warning Storyboard
提问by Simon
I am currently testing out Xcode 9 beta 3 at the time of this writing.
在撰写本文时,我目前正在测试 Xcode 9 beta 3。
When viewing the storyboard I am receiving a list of warnings indicating that in other languages/regions my fixed constraint will pose an issue.
在查看故事板时,我收到了一个警告列表,表明在其他语言/地区,我的固定约束会造成问题。
The application is fairly complex and many views are experiencing these warnings.
该应用程序相当复杂,许多视图都遇到这些警告。
The warning is:
警告是:
Certain autolayout constraint combinations may result in an appropriate layout in the current development language but will pose issues in other languages and regions.
Certain autolayout constraint combinations may result in an appropriate layout in the current development language but will pose issues in other languages and regions.
I know that the app will not be used in any other languages anytime soon.
我知道该应用程序不会很快以任何其他语言使用。
Is there any way to turn just this warning off? It sounds silly but I can not stand seeing all my views with the yellow the warning icon and count at the top (110 warnings!)
有什么办法可以关闭这个警告吗?这听起来很傻,但我无法忍受看到我所有的观点都带有黄色警告图标并在顶部计数(110 个警告!)
回答by allenh
The source of the unwanted warnings is that Xcode defaults to having storyboards "prepared" for localization. They are "prepared" by setting them up using base internationalization.
不需要的警告的来源是 Xcode 默认为本地化“准备”故事板。它们通过使用基础国际化进行设置来“准备” 。
To completely disablethis warning in a particular storyboard, you need to let Xcode know that the storyboard should not be considered localizable. The easiest way I was able to do this was to simply move the storyboard file from the Base.lproj
folder up one level and re-add the file to the project. Once I did that, the warnings went away.
要在特定情节提要中完全禁用此警告,您需要让 Xcode 知道不应将情节提要视为可本地化。我能够做到这一点的最简单方法是简单地将故事板文件从Base.lproj
文件夹上移一层,然后将该文件重新添加到项目中。一旦我这样做了,警告就消失了。
Steps
脚步
This process should work with old and new projects. Tested on Xcode 9.1 using a project created with Xcode 9.1
这个过程应该适用于新旧项目。使用 Xcode 9.1 创建的项目在 Xcode 9.1 上进行测试
- Move the storyboard from the
Base.lproj
folder up one level via Finder - Delete the storyboard reference from your project via Xcode
- Drag and drop (or otherwise re-add) the storyboard to your project
- Verify using the File Inspector that the storyboard no longer has base localization
- 通过 Finder将故事板从
Base.lproj
文件夹上移一级 - 通过 Xcode从您的项目中删除故事板参考
- 将故事板拖放到(或以其他方式重新添加)到您的项目中
- 使用文件检查器验证故事板不再具有基本本地化
Pictorial Walkthrough
图片演练
Xcode defaults to having storyboards "prepared" for localization
Xcode 默认为本地化“准备”故事板
Move your storyboard files out of the Base.lproj folder to prevent the warnings
将故事板文件移出 Base.lproj 文件夹以防止出现警告
Delete the file reference
删除文件引用
Re-add the storyboard
重新添加故事板
You'll see the "Localize..."button when you've succeeded
成功后,您将看到“本地化...”按钮
If you want to localize in the future
如果你以后想本地化
Just tap the "Localize..." button and follow the prompts from Xcode. Additionally, you'll actually need to address the warnings that Xcode is telling you about. There are various ways to address them, I recommend this questionto get started.
只需点击“本地化...”按钮并按照 Xcode 的提示进行操作。此外,您实际上需要解决 Xcode 告诉您的警告。有多种方法可以解决这些问题,我建议从这个问题开始。
For a video demonstration of the process, watch this screen recording
有关该过程的视频演示,请观看此屏幕录制
回答by John
Assuming your app is not localized, you need to restore the Localize setting in your storyboard. One of ours was set to English. Uncheck the English box, or whatever yours is set to. The storyboard is in a folder with the language code, en for English. Unchecking this box will remove it from the project directory since the App is no longer looking for the en folder. Find the storyboard in the finder folder, move it from the en folder, then drag it back into the project. Make sure the Target Membership is checked. Clean, close, open, force quit, etc as necessary and you should be good to go! We had 360 warnings in one storyboard so it was nice to get this resolved!
假设您的应用程序未本地化,您需要恢复故事板中的本地化设置。我们的一个设置为英语。取消选中英文框,或您设置的任何内容。故事板位于一个包含语言代码的文件夹中,en 代表英语。取消选中此框会将其从项目目录中删除,因为应用程序不再查找 en 文件夹。在 finder 文件夹中找到 storyboard,将它从 en 文件夹中移动,然后将其拖回项目中。确保选中目标成员资格。根据需要清洁、关闭、打开、强制退出等,您应该很高兴!我们在一个故事板中有 360 个警告,所以很高兴解决这个问题!
回答by boherna
You can also remove the Localization Issue warning by simply embedding the label or button in a transparent view. Then remove the fix width constraint from the label or button and set it to that container view instead.
您还可以通过在透明视图中简单地嵌入标签或按钮来删除本地化问题警告。然后从标签或按钮中删除固定宽度约束并将其设置为该容器视图。
By using a container view you can silence the warning and still be able to localize the storyboard. Sometimes you need to have a label or button with a fix width even if the language is going to change, and if you are sure the fix width is big enough it shouldn't be a problem but Xcode doesn't know that, that's why you get the warning ;-)
通过使用容器视图,您可以使警告静音,并且仍然能够本地化故事板。有时即使语言要改变,你也需要有一个固定宽度的标签或按钮,如果你确定固定宽度足够大,这应该不是问题,但 Xcode 不知道,这就是为什么你收到警告;-)
回答by phatmann
An easy solution: turn off Respect Language Direction for each problematic constraint.
一个简单的解决方案:为每个有问题的约束关闭尊重语言方向。