Fórmulas de tradução: localização complicada para iOS e outros

O enredo dessa história se desenvolveu quando tive a oportunidade de implementar uma das tarefas de produto de nossa empresa Jivo para a plataforma iOS. Mas vou começar com uma breve introdução.

A localização é um dos tópicos frequentemente discutidos no desenvolvimento móvel.

Principalmente neste tópico em relação à plataforma iOS, os seguintes aspectos são afetados:

  • serviços para simplificar a organização e sincronização das traduções;

  • melhores práticas para traduzir arquivos xib;

  • add-ins auxiliares de tempo de compilação para verificação de tradução.

No entanto, nossa história não é sobre isso. Para sincronizar as traduções, integramos com sucesso um serviço de terceiros em nossa empresa, em vez de arquivos xib, preferimos o código, e não usamos add-ons de tempo de compilação ainda (no entanto, existem ideias sobre a implementação).

Nossa história é sobre como um dia tivemos a chance de enfrentar uma tarefa em que praticamente tivemos que fazer malabarismos com traduções de uma mesma frase, que foi ligeiramente modificada dependendo do contexto.

Como tudo começou

Nosso produto agora possui funcionalidade para configuração de lembretes. Os lembretes podem ser úteis caso a operadora deseje retornar ao cliente um pouco mais tarde. Por exemplo, para esclarecer se algum tempo depois da consulta surgiram dúvidas adicionais, o que ajuda a aumentar a fidelidade. Um lembrete para um determinado tempo pode ser definido para você ou para outro operador, e você pode, opcionalmente, especificar um comentário de texto (descrição), se necessário.

É claro que o fato de definir tal lembrete é duplicado na fita de diálogo por uma mensagem do sistema. E foi precisamente aqui que a dificuldade foi descoberta: dependendo da configuração do lembrete, a etiqueta de informação pode parecer completamente diferente. Por exemplo (da versão em inglês da 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

( , , ) , . .

A biblioteca é escrita em C ++ e também existe um wrapper em C e Swift .

For Swift fornece conectividade por meio de CocoaPods e Swift, o Gerenciador de Pacotes .

Repositório GitHub




All Articles