【发布时间】:2021-09-15 06:10:40
【问题描述】:
我在第一次使用应用时加载的 swift 文件中有以下内容:
let descriptions = [NSLocalizedString("""
Hyperpolyglot will help you learn words and phrases in
up to 10 languages. Add languages, words and phrases
with the aid of phrase books. Learn a word in many
languages while learning it in one.
Use your native keyboard and transliteration, if you just
want to speak a language. Take it up a level! Switch
keyboard languages, and also learn to read and write.
""", comment: "Welcome screen 1"),
NSLocalizedString("""
Associate a word with an image or drawing. Grab images
from your favourite search engine, or make your own line
drawings.
Do you really know the word? Answer foreign words
which have missing letters.
Tap the lightbulb if you need hints.
""", comment: "Welcome screen 2"),
NSLocalizedString("""
Buy the full copy to add unlimited words and unlock the
drawing canvas!
""", comment: "Welcome screen 3")]
然后我尝试在 localizable.strings(德语)中创建德语本地化:
/* Welcome screen 1 */
"""
Hyperpolyglot will help you learn words and phrases in
up to 10 languages. Add languages, words and phrases
with the aid of phrase books. Learn a word in many
languages while learning it in one.
Use your native keyboard and transliteration, if you just
want to speak a language. Take it up a level! Switch
keyboard languages, and also learn to read and write.
""" = """
Hyperpolyglot hilft Ihnen, Wörter und Sätze in bis zu
10 Sprachen zu lernen. Fügen Sie Sprachen, Wörter und
Sätze mit Hilfe von Sprachführern hinzu. Lernen Sie ein
Wort in vielen Sprachen, während Sie es in einer lernen.
Verwenden Sie Ihre native Tastatur und Transliteration,
wenn Sie nur eine Sprache sprechen möchten. Bring es auf
ein Level! Wechseln Sie die Tastatursprachen und lernen
Sie auch, zu lesen und zu schreiben.
"""
但我在编译时收到以下错误:
“读取失败:无法解析属性列表,因为输入数据的格式无效”
甚至可以在可本地化的文件中使用多行字符串吗?
当我本地化我的字符串时,我想利用多行字符串的段落格式化功能。
【问题讨论】:
-
正如马丁在他的回答末尾暗示的那样,您应该使用短代码作为键,而不是实际文本。在字符串文件中,对包括基础语言在内的所有语言执行
"welcomescreen.label1" = "your text";然后"welcomescreen.label2" = "some other text";等操作,并将此编码键与 NSLocalizedString 一起使用,而不是实际文本。
标签: swift localization multilinestring ipados