The plot of this story developed when I had the opportunity to implement one of the product tasks of our company Jivo for the iOS platform. But I'll start with a short introduction.
Localization is one of the frequently discussed topics in mobile development.
Mainly on this topic with regard to the iOS platform, the following aspects are affected:
services to simplify the organization and synchronization of translations;
best-practice for translating xib files;
auxiliary compile-time add-ins for translation verification.
However, our story is not about that. To synchronize translations, we have successfully integrated a third-party service in our company, instead of xib files, we prefer code, and we do not use compile-time add-ons yet (however, there are thoughts on implementation).
Our story is about how one day we had a chance to face a task in which it was necessary to practically juggle translations of the same phrase in meaning, which was slightly modified depending on the context.
How it all started
Our product now has functionality for setting reminders. Reminders can be useful in case the operator wishes to return to the client a little later. For example, to clarify whether additional questions have arisen some time after the consultation, which helps to increase loyalty. A reminder for a certain time can be set for yourself or for another operator, and you can optionally specify a text comment (description), if needed.
Of course, the fact of setting such a reminder is duplicated in the dialogue tape by a system message. And it was precisely here that the difficulty was discovered: depending on the configuration of the reminder, the information label can look completely different. For example (from the English version of the interface):
◼︎ 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
( , , ) , . .
The library is written in C ++ , and there is also a wrapper in C and Swift .
For Swift provides connectivity through CocoaPods and Swift the Package Manager .