6

I have a PostgreSQL database. It has a table which stores menu items(labels).These menu items are stored in English. is there any way to convert these stored items (100+) to Japanese language by using localization feature? because my customer box is UNIX with locale set to Japanese.

1
  • 3
    A "locale" only defines how characters are compared (and sorted). It does not do any automatic translation for you.
    – user330315
    Jul 16, 2014 at 6:52

1 Answer 1

5

Reading between the lines, I'd say your database is in iso-8869-1 or WIN1252 encoding, which are 1-byte encodings for English languages.

If so, while you could transcode to a Japanese-specific encoding, they're mostly quite limited - both in their coverage of English (Roman) characters, and their coverage of Kanji/Hiragana. Japanese doesn't work wonderfully in a 1-byte encoding. Shift-JIS was an attempt to work around that, but it's an awful text encoding to work with and PostgreSQL will refuse to run with it.

Instead, convert the database to utf-8. This will support all your existing content and all new content. UTF-8 will work for any language.

To do so:

CREATE DATABASE mydb_new ENCODING 'UTF-8' 
    LC_COLLATE 'jp_JA.UTF-8' LC_CTYPE 'jp_JA.UTF-8';

then pg_dump the old database, and pg_restore to the new database. Afterwards you can rename the databases to swap them over.

All characters in latin-1 are valid in utf-8, so there won't be issues loading the dump.

You/your customer might need to generate/install the ja_JP.UTF-8 locale (if on Linux/BSD). How to do that is somewhat distro/platform specific.

2
  • LC_COLLATE and LC_CTYPE should be ja_JP.UTF-8 (not jp_JA) Mar 20, 2018 at 2:36
  • 1
    It is likely TEMPLATE template0 is required to add in the CREATE DATABASE statement. See an answer. Mar 20, 2018 at 2:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.