Swift中的本地化2 [英] Localization in Swift 2

查看:164
本文介绍了Swift中的本地化2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想本地化我的应用程序;我正在使用Swift 2.我遵循本教程但是我遇到了2个问题。



1。两种语言的本地化图像消失



我以相同的方式为德语英语本地化了多个图像。一组图像(图像的en和de版本)对于两种语言都消失了。我添加了它们,它们位于项目的文件夹中,我无法发现与我本地化的其他图像有任何区别。



我试过




  • 清理和运行项目(无错误

  • 删除了图片和再次添加它们

  • 已删除并添加了本地化



...没有任何帮助。有什么想法?



2。错误w / NSLocalizedString & Localizable.strings



我创建了 Localizable.strings 用于本地化我的应用程序的字符串。这里是我让他们本地化的:

  button.setTitle(NSLocalizedString( 按钮名称 评论: 为myButton),forState :.Normal)

Localizable.strings 英语我添加:

 buttonTitle=MyButton

...和德语

 buttonTitle=MeinButton

现在,Xcode没有显示代码中的任何错误,但它表示


读取失败:

数据无法读取,因为它不是格式正确。




有什么想法吗?

提前谢谢:)






编辑



问题#2已解决,我错过了; 。由于codingVoldemort!


解决方案

  • 我想你已经错过了分号在每个键值对之后的Localizable.strings上。


  • I want to localize my application; I am using Swift 2. I followed this tutorial but I experience 2 issues.

    1. Localized image disappears for both languages

    I localized multiple images the same way for German and English. One set of images (the en and de versions of an image) disappear for both languages. I added them, they are in the project's folder and I can not spot any difference to other images I localized.

    I tried

    • cleaning and running the project (no errors)
    • removed the images and added them again
    • removed and added the localization

    …nothing helped. Any idea?

    2. Error w/ NSLocalizedString & Localizable.strings

    I created a Localizable.strings for localizing my app's strings. Here is how I make them localizable:

    button.setTitle(NSLocalizedString("buttonTitle", comment: "MyButton"), forState: .Normal)
    

    In the Localizable.strings for English I added:

    "buttonTitle" = "MyButton"
    

    …and for German:

    "buttonTitle" = "MeinButton"
    

    Now, Xcode does not show any errors in code but it says

    Read failed:
    The data couldn't be read because it isn't in the correct format.


    Any ideas?
    Thank you in advance :)


    Edit

    Issue #2 was resolved, I missed a ; there. Thanks to codingVoldemort!

    解决方案

    1. I think you have missed the semi-colon on the Localizable.strings after each key-value pair.

    这篇关于Swift中的本地化2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆