Змініть локалізацію віджета чату в iOS SDK

Забезпечте багатомовну підтримку в iOS SDK
Написано Konstantine
Оновлено 2 тижні тому

Ви можете змінити будь-який текст в iOS SDK HelpCrunch і додати переклади кількома мовами. Мова інтерфейсу чату та мова Бази знань налаштовуються окремо:

  • Тексти чату беруться з файлу Localizable.strings у вашому застосунку.
  • Мова Бази знань задається методом setKBLanguage (iOS SDK 4.5.7 і новіші).

Змініть тексти (одна мова)

Якщо ваш застосунок використовує одну мову, достатньо перевизначити лише ті тексти, які ви хочете змінити.

  1. У Xcode оберіть File → New → File… → Strings File і назвіть файл Localizable.strings. Якщо такий файл у проєкті вже є, використовуйте його.
  2. Додайте SDK string resource, які хочете змінити. Копіювати весь список не потрібно. Ключі, які ви не перевизначили, зберігають значення за замовчуванням.
"helpcrunch.chat.waiting-message" = "Шукаємо вільного агента, хвилинку…";
"helpcrunch.kb.title" = "Привіт 👋 Чим можемо допомогти?";

Повний список ключів наведено нижче.


Додайте кілька мов

Щоб показувати чат кількома мовами, створіть окрему версію Localizable.strings для кожної з них. iOS обере версію, яка відповідає мові пристрою або застосунку.

  1. Додайте мову до проєкту: оберіть проєкт → Info → Localizations → + і виберіть мову (наприклад, іспанську).
  2. Оберіть Localizable.strings у Project Navigator і відкрийте File inspector (Alt + Cmd + 1).
  3. Натисніть Localize… і позначте в списку всі потрібні мови. Xcode створить окремий файл для кожної мови (наприклад, es.lproj/Localizable.strings).
  4. Додайте перекладені тексти до файлу кожної мови:
/* es.lproj/Localizable.strings */
"helpcrunch.chat.waiting-message" = "Buscando un agente, un momento…";
"helpcrunch.kb.title" = "Hola 👋 ¿Cómo podemos ayudarte?";

Повний список ключів наведено нижче.


Задайте мову Бази знань

Тексти чату беруться з файлів Localizable.strings, а в Бази знань є власне налаштування мови. Щоб його задати, використовуйте setKBLanguage:

Swift

Параметри:
locale: string: дволітерний код мови (ISO 639-1), наприклад en, es, de.

HelpCrunch.setKBLanguage(String);

Коли користувач перемикає мову застосунку на іспанську, ви можете показати Базу знань іспанською:

HelpCrunch.setKBLanguage("es");

Objective-C

[HelpCrunch setKBLanguage:@"es"]

Як це працює

  • Метод одразу перемикає мову Бази знань. Його можна викликати будь-коли.
  • Метод має пріоритет над вибором користувача. Якщо користувач обрав мову вручну, а потім метод викликали, База знань перемкнеться на передану вами мову.
  • Якщо метод не викликати, нічого не зміниться: База знань залишиться мовою, яку обрав користувач.

Важливо: якщо викликати метод під час кожного запуску застосунку або SDK, мова Бази знань скидатиметься щоразу. Мова, яку користувач обрав вручну, діятиме лише до наступного перезапуску.

Порада: щоб зберегти вибір користувача, викликайте метод лише тоді, коли це справді потрібно, наприклад коли користувач змінює мову вашого застосунку. Не викликайте його під час кожного запуску застосунку або SDK.


Ключі локалізації

"helpcrunch.navigation.button.close" = "Close";

"helpcrunch.attachment.photo" = "Take a Photo";
"helpcrunch.attachment.library" = "Select from a Library";
"helpcrunch.attachment.file" = "Select file";

"helpcrunch.agent.agents" = "Agents";
"helpcrunch.agent.is-typing" = "%@ is typing...";
"helpcrunch.agent.are-typing" = "%@ are typing...";
"helpcrunch.agent.and-more" = " and %i more";

"helpcrunch.chat.file.uploaded" = "uploaded";
"helpcrunch.chat.file.downloaded" = "downloaded";

"helpcrunch.chat.alert.deleted" = "This chat was removed. You'll be redirected to the chat list.";
"helpcrunch.chat.alert.filesize-exceeded" = "The maximum supported file size is %.0f MB.";

"helpcrunch.alert.button.ok" = "OK";

"helpcrunch.connection.unknown-error" = "Oops, something went wrong";
"helpcrunch.connection.offline" = "No internet connection";

"helpcrunch.prechatForm.name" = "Name";
"helpcrunch.prechatForm.email" = "Email";
"helpcrunch.prechatForm.company" = "Company";
"helpcrunch.prechatForm.phone" = "Phone number";
"helpcrunch.prechatForm.department" = "Choose a department";
"helpcrunch.prechatForm.continue" = "Continue";
"helpcrunch.prechatForm.acceptance-title" = "I have read and accept the";
"helpcrunch.prechatForm.acceptance-name" = "Privacy Policy";
"helpcrunch.prechatForm.top-message" = "We respond within 2 minutes most of the time. Otherwise, we'll drop you an email.";

"helpcrunch.kb.title" = "Hello 👋 How can we help?";
"helpcrunch.kb.search-result" = "Search result: %@";
"helpcrunch.kb.search-result.none.title" = "There are no articles";
"helpcrunch.kb.search-result.none.description" = "We're working on adding our help articles.\nYou'll find them here very soon.";
"helpcrunch.kb.search-articles" = "Search articles";
"helpcrunch.kb.rate.title" = "DID THIS ANSWER YOUR\nQUESTION?";
"helpcrunch.kb.tab" = "Search";
"helpcrunch.kb.section.show-articles" = "SHOW ALL";
"helpcrunch.kb.section.hide-articles" = "HIDE ARTICLES";
"helpcrunch.kb.article.author" = "Written by %@";
"helpcrunch.kb.article.updated" = "Updated %@";

"helpcrunch.kb.language.article-not-translated" = "This article isn't translated into %@. You may choose another language:";
"helpcrunch.kb.protected.title.password" = "The knowledge base is protected by password";
"helpcrunch.kb.protected.field.password" = "Password";
"helpcrunch.kb.protected.button.sign-in" = "Sign In";
"helpcrunch.kb.protected.title.incorrect-password" = "Password is incorrect";
"helpcrunch.kb.protected.title.ip-prohibited" = "Access to knowledge base is prohibited";

"helpcrunch.chat.tab" = "Ask";

"helpcrunch.chat.waiting-message" = "Searching for a free agent. Please hold on.";
"helpcrunch.chat.offline-message" = "Sorry, we are not available now. We've got your message though and we'll reply to you as soon as we can.";
"helpcrunch.chat.message-chat-closed" = "This chat is closed";
"helpcrunch.chat.message-placeholder" = "Type message";
"helpcrunch.chat.status.closed" = "CLOSED";

"helpcrunch.chat.rating.very-poor" = "Very poor";
"helpcrunch.chat.rating.poor" = "Poor";
"helpcrunch.chat.rating.avarage" = "Average";
"helpcrunch.chat.rating.great" = "Good";
"helpcrunch.chat.rating.excellent" = "Excellent";
"helpcrunch.chat.rating.title" = "How do you rate your customer\nservice experience?";

"helpcrunch.chat.message.tech.status" = "Chat marked as %@ by %@";
"helpcrunch.chat.message.tech.status-without-agent" = "Chat marked as %@";
"helpcrunch.chat.message.tech.rated" = "Chat rated %@";
"helpcrunch.chat.message.tech.request-rating" = "Please rate this chat";

"helpcrunch.chats.date.now" = "Now";
"helpcrunch.chats.date.hours" = "h";
"helpcrunch.chats.date.minutes" = "m";
"helpcrunch.chats.start" = "Start new conversation";
"helpcrunch.chats.limit-exceeded" = "You've reached the conversation limit.\nPlease, try again later.";

"helpcrunch.chat.more.end-chat" = "End this chat";

"helpcrunch.chatbot.boolean.yes" = "Yes";
"helpcrunch.chatbot.boolean.no" = "No";

"helpcrunch.cancel" = "Cancel";

"helpcrunch.chat.message.status.new" = "New";
"helpcrunch.chat.message.status.open" = "Open";
"helpcrunch.chat.message.status.pending" = "Pending";
"helpcrunch.chat.message.status.onhold" = "On-hold";
"helpcrunch.chat.message.status.closed" = "Closed";
Чи була наша стаття корисною?