【发布时间】:2020-12-17 19:19:54
【问题描述】:
我正在 Android Studio 中进行一些翻译,但遇到了错误。
我有一个句子和这种格式的日期。\'Estimated Time: \'h:mm a
这很好用。
但是,翻译成法语会在 d'atttente 一词中添加一个撇号。\'Temps d\'attente estimé: \'h:mm a
这最终会提前终止字符串文字,并且我的日期格式化程序崩溃。
有没有一种方法可以在我的 strings.xml 文件中使用带撇号的句子和日期格式?
提前致谢!
编辑:
这是来自 logcat 的信息,
java.lang.IllegalArgumentException: Unknown pattern letter: t
at org.threeten.bp.format.DateTimeFormatterBuilder.parsePattern(DateTimeFormatterBuilder.java:1470)
at org.threeten.bp.format.DateTimeFormatterBuilder.appendPattern(DateTimeFormatterBuilder.java:1382)
at org.threeten.bp.format.DateTimeFormatter.ofPattern(DateTimeFormatter.java:788)
at com.brunswickbowling.sync.passport.extensions.ContextExtKt.getDateTimeFormatter(ContextExt.kt:41)
at com.brunswickbowling.sync.passport.extensions.TextViewExtKt.setText(TextViewExt.kt:98)
不知道为什么我得到Unknown pattern letter: t,但是当我删除 d'attente 中的撇号时,它工作正常。可能是什么
这里是 XML 格式,
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="format_waitlist_eta">\'Temps d\'attente estimé: \'h:mm a</string>
</resources>
编辑和回答:
原来需要第四个\' 才能不提前终止字符串。所以字符串最终看起来像\'Temps d\'\'attente estimé: \'h:mm a。
【问题讨论】:
-
您说您的日期格式化程序崩溃了。请更新您的问题并添加来自 logcat 的错误文本和堆栈跟踪。此外,发生错误的代码行也会对您有所帮助。
-
您究竟是如何用 XML 编写导致字符串提前终止的?
-
@RyanM 我已更新问题以包含 xml。感谢您的帮助。
-
@Vadik,我添加了一些 logcat 信息。也许是由于那个撇号之后的日期格式,因为我收到了那个错误?有什么阻碍,但我不确定是什么。
标签: android xml string localization