当我有机会为iOS平台实现我们公司Jivo的产品任务之一时,这个故事的情节发展了。但我将从简短的介绍开始。
本地化是移动开发中经常讨论的主题之一。
主要是关于iOS平台的主题,以下方面会受到影响:
简化翻译的组织和同步的服务;
翻译xib文件的最佳实践;
用于验证翻译的辅助编译时附加程序。
但是,我们的故事并非如此。为了同步翻译,我们已经在公司中成功集成了第三方服务,而不是xib文件,我们更喜欢代码,并且不使用编译时加载项(但是,有实现的想法)。
我们的故事讲述的是,有一天我们有机会面对一项任务,其中有必要对意义上相同的短语进行翻译,根据上下文的不同对其进行了稍微的修改。
一切如何开始
我们的产品现在具有设置提醒的功能。如果操作员希望稍后再返回给客户,提醒可能会很有用。例如,澄清咨询后一段时间是否还会出现其他问题,这有助于提高忠诚度。您可以为自己或其他操作员设置特定时间的提醒,并且可以根据需要选择指定文本注释(说明)。
当然,设置这样的提醒的事实在对话带中通过系统消息被复制。正是在这里发现了难题:根据提醒的配置,信息标签看起来可能完全不同。例如(从界面的英文版开始):
◼︎ You created the reminder for agent Alex on 08/29/20 at 4:30 PM
◼︎ Agent Nick created the reminder "Ask about any issue happened since our call" on 10/03/20 at 11:30 AM
◼︎ Agent Alex completed the reminder on 12/05/20 at 5:00 PM
, :
◼︎ –
◼︎
◼︎
◼︎ – , ,
, 32 . , , , . , .
, « » , :
// either...
let caption = format(
"REMINDER_CREATE_SELF_FOR_SELF", // !!!
reminder.time)
// or...
let caption = format(
"REMINDER_CREATE_ANOTHER_WITH_COMMENT_FOR_SELF", // !!!
reminder.author.name,
reminder.comment,
reminder.time)
// etc...
. , , , . , , . , :
if reminder.author.isMe {
slices += [format("REMINDER_AUTHOR_SELF")]
}
else {
slices += [format("REMINDER_AUTHOR_ANOTHER", reminder.author.name)]
}
if let comment = reminder.comment {
slices += [format("REMINDER_COMMENT", comment)]
}
if reminder.target.isMe {
slices += [format("REMINDER_FOR_SELF")]
}
else {
slices += [format("REMINDER_FOR_ANOTHER", reminder.target.name)]
}
slices += [format("REMINDER_TIME", reminder.time)]
let caption = slices.joined()
, - . .
. bb- , . , , , . « ».
( ). , , .
– , , $creatorName
, , .
– , , $[Agent $creatorName ## You]
; - Agent $creatorName
You
, ##
; , ; . , , ( ) ; .
– , , , $[Agent $creatorName ## :another: Another agent ## You]
; - Agent $creatorName
, Another agent
You
; Another agent
another
, , , ( ).
. , :
◼︎ Agent Nick created the reminder on 10/03/20 at 11:30 AM
◼︎ You created the reminder "Ask about any issue happened since our call" on 10/03/20 at 11:30 AM
◼︎ Agent Nick created the reminder "Ask about any issue happened since our call" on 10/03/20 at 11:30 AM
◼︎ You created the reminder for Alex on 10/03/20 at 11:30 AM
:
$[Agent $creatorName ## You] created the reminder $["$comment"] $[for $targetName] on $date at $time
, . , , . , ( Swift, C++, ).
:
let parser = PureParser()
let formula = "$[Agent $creatorName ## You] created the reminder $[\"$comment\"] $[for $targetName] on $date at $time"
parser.assign(variable: "creatorName", value: "Nick")
parser.assign(variable: "date", value: "10/03/20")
parser.assign(variable: "time", value: "11:30 AM")
let result = parser.execute(formula, collapseSpaces: true, resetOnFinish: true)
print(result)
// Agent Nick created the reminder on 10/03/20 at 11:30 AM
:
let parser = PureParser()
let formula = "$[Agent $creatorName ## You] created the reminder $[\"$comment\"] $[for $targetName] on $date at $time"
parser.assign(variable: "comment", value: "Ask about any issue happened since our call")
parser.assign(variable: "date", value: "10/03/20")
parser.assign(variable: "time", value: "11:30 AM")
let result = parser.execute(formula, collapseSpaces: true, resetOnFinish: true)
print(result)
// You created the reminder "Ask about any issue happened since our call" on 10/03/20 at 11:30 AM
:
let parser = PureParser()
let formula = "$[Agent $creatorName ## You] created the reminder $[\"$comment\"] $[for $targetName] on $date at $time"
parser.assign(variable: "creatorName", value: "Nick")
parser.assign(variable: "comment", value: "Ask about any issue happened since our call")
parser.assign(variable: "date", value: "10/03/20")parser.assign(variable: "time", value: "11:30 AM")
let result = parser.execute(formula, collapseSpaces: true, resetOnFinish: true)
print(result)
// Agent Nick created the reminder "Ask about any issue happened since our call" on 10/03/20 at 11:30 AM
:
let parser = PureParser()
let formula = "$[Agent $creatorName ## You] created the reminder $[\"$comment\"] $[for $targetName] on $date at $time"
parser.assign(variable: "targetName", value: "Alex")
parser.assign(variable: "date", value: "10/03/20")
parser.assign(variable: "time", value: "11:30 AM")
let result = parser.execute(formula, collapseSpaces: true, resetOnFinish: true)
print(result)
// You created the reminder for Alex on 10/03/20 at 11:30 AM
: ?
let parser = PureParser()
let formula = "$[Agent $creatorName ## :another: Another agent ## You] created the reminder $[\"$comment\"] $[for $targetName] on $date at $time"
parser.activate(alias: "another", true)
parser.assign(variable: "date", value: "10/03/20")
parser.assign(variable: "time", value: "11:30 AM")
let result = parser.execute(formula, collapseSpaces: true, resetOnFinish: true)
print(result)
// Another agent created the reminder on 10/03/20 at 11:30 AM
( , , ) , . .
该库用C ++编写,并且在C和Swift中也有一个包装器。
对于Swift,它通过CocoaPods和Swift软件包管理器提供连接。