Move translations from .properties file to the impex file for LocalizationEntry table

Problem: move many translations from the base_**.properties file to the impex file for LocalizationEntry table.

Lets say in the base_**.properties for German language we have tons of translation like this:

account.confirmation.address.added=Adresse erfolgreich erstellt
account.confirmation.address.deleted=Adresse erfolgreich gelöscht

and we want to move them to an impex file that creates LocalizationEntry for every one of them.

INSERT_UPDATE LocalizationEntry; code[unique = true]; translation[lang = de]
; account.confirmation.address.added ; "Adresse erfolgreich erstellt"
; account.confirmation.address.deleted ; "Adresse erfolgreich gelöscht"

Why? This way we can impex them once and let customer maintain translations in backoffice and be sure we don’t overwrite them with default values when doing platform update.

We can do it in any text editor that supports Regex replace. In IntelliJ you can do it from the Replace dialog (Ctrl+R).

1. Replace " with ""

2. In the Regex mode replace



; $1 ; "$2" 

The first command escapes quotes with double-quotes inside translated strings, the second one encapsulates them into double quotes thus escaping semicolons and other special chars. Solution based on this answer from experts.

Reversed process

To do a reverse operation we will need a little more work:

  1. In Regex mode replace
    (this replaces translations enclosed by quotes)
  2. Also in Regex mode replace
    (this handles the translations written in plain text without quotes)
  3. Replace "" with" unescaping quotes

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.