Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
i18nize Scala programs
à la gettext
Episode 39, Wed, Aug 12, 2015
Ngoc Dao
About the speaker
● Ngoc Dao
● Joined Atlassian since May
● Favorite languages:
Ruby, Erlang, Scala
● Favorite languages:
Ruby, Erlang, Scala
● My Scala style:
Using Scala as if
Scala =
Java (performance, libs eco) +
Ruby ...
● Don’t know Scalaz/Haskell (yet)
↑↑↑
Struggling with
monadic talks at ScalaSyd
English is not my native language
● From Viet Nam
● 15 years in Japan
↑↑↑
i18n is important to me
Given this program:
printf("My name is %s.", myName)
Given this program:
printf("My name is %s.", myName)
Let’s i18nize it in gettext style!
(I won’t go into details of .prope...
(1) Mark the strings we want to translate
printf(t("My name is %s."), myName)
i18n.pot template file:
msgid "My name is %s."
msgstr ""
(2) Extract to a template file
(1) Mark the strings we want to tr...
i18n.pot template file:
msgid "My name is %s."
msgstr ""
fr.po language file:
msgid "My name is %s."
msgstr "Je m'appelle ...
When strings in the program change, how to
update (add, remove, modify) language files
efficiently?
When strings in the program change, how to
update (add, remove, modify) language files
efficiently?
● Automatically copy s...
When strings in the program change, how to
update (add, remove, modify) language files
efficiently?
● Automatically copy s...
When strings in the program change, how to
update (add, remove, modify) language files
efficiently?
● Automatically copy s...
fr.po language file:
msgid "My name is %s."
msgstr "Je m'appelle %s."
ja.po language file:
msgid "My name is %s."
msgstr "...
printf(t("My name is %s."), myName)
printf("Je m’appelle %s.", myName)
(5) At run time, the marker acts as a
function to r...
gettext is quite advanced
● Allow specifying context
(one string may be translated to
different strings, depending on
cont...
print(t("Hello"))
print(tc("Casual", "Hello"))
fr.po language file:
msgid "Hello"
msgstr "Bonjour"
msgctxt "Casual"
msgid ...
gettext is quite advanced
● Allow specifying singular/plural rules
(different languages may have
different singular/plural...
print(tn(
"I have one apple",
"I have %d apples",
numApples
))
Singular
Plural
Depending on this value
fr.po language file:
msgid ""
msgstr "Plural-Forms: nplurals=2; plural=n>1;"
msgid "I have one apple"
msgid_plural "I have...
Demo
I’ll introduce some tools
Hello.scala
println("Hello world")
Mark and extract i18n strings
Mark and extract i18n strings
Tool:
https://github.com/xitrum-framework/scala-xgettext
It’s a Scala compiler plugin, to ex...
Mark and extract i18n strings
Tool:
https://github.com/xitrum-framework/scala-xgettext
It’s a Scala compiler plugin, to ex...
● scala-xgettext can also extracts i18n strings
from view templates
● as long as the templates are converted to
Scala sour...
● scala-xgettext can also extracts i18n strings
from view templates
● as long as the templates are converted to
Scala sour...
Translate language template file
Translate language template file
Tool:
Any text editor
Translate language template file
Tool:
Any text editor
Very convenient GUI editor:
https://poedit.net/
Load language file
Tool:
https://github.com/xitrum-framework/scaposer
It’s a Scala parser to transform .po text file into
...
Poedit demo: Update i18n strings
● Add, modify, remove i18n strings in program
● Regenerate i18n.pot file
● Use Poedit to ...
Demo source code:
https://github.com/xitrum-framework/scala-xgettext-presentation
If you use Play framework:
https://githu...
Upcoming SlideShare
Loading in …5
×

of

I18nize Scala programs à la gettext Slide 1 I18nize Scala programs à la gettext Slide 2 I18nize Scala programs à la gettext Slide 3 I18nize Scala programs à la gettext Slide 4 I18nize Scala programs à la gettext Slide 5 I18nize Scala programs à la gettext Slide 6 I18nize Scala programs à la gettext Slide 7 I18nize Scala programs à la gettext Slide 8 I18nize Scala programs à la gettext Slide 9 I18nize Scala programs à la gettext Slide 10 I18nize Scala programs à la gettext Slide 11 I18nize Scala programs à la gettext Slide 12 I18nize Scala programs à la gettext Slide 13 I18nize Scala programs à la gettext Slide 14 I18nize Scala programs à la gettext Slide 15 I18nize Scala programs à la gettext Slide 16 I18nize Scala programs à la gettext Slide 17 I18nize Scala programs à la gettext Slide 18 I18nize Scala programs à la gettext Slide 19 I18nize Scala programs à la gettext Slide 20 I18nize Scala programs à la gettext Slide 21 I18nize Scala programs à la gettext Slide 22 I18nize Scala programs à la gettext Slide 23 I18nize Scala programs à la gettext Slide 24 I18nize Scala programs à la gettext Slide 25 I18nize Scala programs à la gettext Slide 26 I18nize Scala programs à la gettext Slide 27 I18nize Scala programs à la gettext Slide 28 I18nize Scala programs à la gettext Slide 29 I18nize Scala programs à la gettext Slide 30 I18nize Scala programs à la gettext Slide 31 I18nize Scala programs à la gettext Slide 32 I18nize Scala programs à la gettext Slide 33 I18nize Scala programs à la gettext Slide 34 I18nize Scala programs à la gettext Slide 35
Upcoming SlideShare
Model with actors and implement with Akka
Next
Download to read offline and view in fullscreen.

3 Likes

Share

Download to read offline

I18nize Scala programs à la gettext

Download to read offline

This presentation explains about GNU gettext and how to internationalize Scala programs in in gettext style.

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

I18nize Scala programs à la gettext

  1. 1. i18nize Scala programs à la gettext Episode 39, Wed, Aug 12, 2015 Ngoc Dao
  2. 2. About the speaker ● Ngoc Dao ● Joined Atlassian since May
  3. 3. ● Favorite languages: Ruby, Erlang, Scala
  4. 4. ● Favorite languages: Ruby, Erlang, Scala ● My Scala style: Using Scala as if Scala = Java (performance, libs eco) + Ruby (human oriented) + Erlang (functional)
  5. 5. ● Don’t know Scalaz/Haskell (yet) ↑↑↑ Struggling with monadic talks at ScalaSyd
  6. 6. English is not my native language ● From Viet Nam ● 15 years in Japan ↑↑↑ i18n is important to me
  7. 7. Given this program: printf("My name is %s.", myName)
  8. 8. Given this program: printf("My name is %s.", myName) Let’s i18nize it in gettext style! (I won’t go into details of .properties style vs gettext style)
  9. 9. (1) Mark the strings we want to translate printf(t("My name is %s."), myName)
  10. 10. i18n.pot template file: msgid "My name is %s." msgstr "" (2) Extract to a template file (1) Mark the strings we want to translate printf(t("My name is %s."), myName)
  11. 11. i18n.pot template file: msgid "My name is %s." msgstr "" fr.po language file: msgid "My name is %s." msgstr "Je m'appelle %s." (2) Extract to a template file (3) Give it to translators (1) Mark the strings we want to translate printf(t("My name is %s."), myName)
  12. 12. When strings in the program change, how to update (add, remove, modify) language files efficiently?
  13. 13. When strings in the program change, how to update (add, remove, modify) language files efficiently? ● Automatically copy similar existing translation to make new translation (marked as “fuzzy” to be modified by a human later)
  14. 14. When strings in the program change, how to update (add, remove, modify) language files efficiently? ● Automatically copy similar existing translation to make new translation (marked as “fuzzy” to be modified by a human later) ● Don’t delete, just comment out dated translations for future references
  15. 15. When strings in the program change, how to update (add, remove, modify) language files efficiently? ● Automatically copy similar existing translation to make new translation (marked as “fuzzy” to be modified by a human later) ● Don’t delete, just comment out dated translations for future references ● In translation files, sort by msgid so that it’s easier to diff versions
  16. 16. fr.po language file: msgid "My name is %s." msgstr "Je m'appelle %s." ja.po language file: msgid "My name is %s." msgstr "%sと申します。" (4) Load language files to program, basically parse the files to key → value data structure vi.po language file: msgid "My name is %s." msgstr "Tôi tên là %s."
  17. 17. printf(t("My name is %s."), myName) printf("Je m’appelle %s.", myName) (5) At run time, the marker acts as a function to replace the given key with its value
  18. 18. gettext is quite advanced ● Allow specifying context (one string may be translated to different strings, depending on context)
  19. 19. print(t("Hello")) print(tc("Casual", "Hello")) fr.po language file: msgid "Hello" msgstr "Bonjour" msgctxt "Casual" msgid "Hello" msgstr "Salut"
  20. 20. gettext is quite advanced ● Allow specifying singular/plural rules (different languages may have different singular/plural rules)
  21. 21. print(tn( "I have one apple", "I have %d apples", numApples )) Singular Plural Depending on this value
  22. 22. fr.po language file: msgid "" msgstr "Plural-Forms: nplurals=2; plural=n>1;" msgid "I have one apple" msgid_plural "I have %d apples" msgstr[0] "J'ai une pomme" msgstr[1] "J'ai %d pommes" Singular/plural rule Special key
  23. 23. Demo I’ll introduce some tools
  24. 24. Hello.scala println("Hello world")
  25. 25. Mark and extract i18n strings
  26. 26. Mark and extract i18n strings Tool: https://github.com/xitrum-framework/scala-xgettext It’s a Scala compiler plugin, to extract i18n strings at compile time.
  27. 27. Mark and extract i18n strings Tool: https://github.com/xitrum-framework/scala-xgettext It’s a Scala compiler plugin, to extract i18n strings at compile time. ↑↑↑ Neat! Just compile Scala source code and get the strings. Scala is powerful
  28. 28. ● scala-xgettext can also extracts i18n strings from view templates ● as long as the templates are converted to Scala source code and compiled Mark and extract i18n strings
  29. 29. ● scala-xgettext can also extracts i18n strings from view templates ● as long as the templates are converted to Scala source code and compiled ↑↑↑ It works for all popular Scala template engines like Scalate, Scalatags, Twirl (Play framework template engine) Mark and extract i18n strings
  30. 30. Translate language template file
  31. 31. Translate language template file Tool: Any text editor
  32. 32. Translate language template file Tool: Any text editor Very convenient GUI editor: https://poedit.net/
  33. 33. Load language file Tool: https://github.com/xitrum-framework/scaposer It’s a Scala parser to transform .po text file into key → value data structure
  34. 34. Poedit demo: Update i18n strings ● Add, modify, remove i18n strings in program ● Regenerate i18n.pot file ● Use Poedit to update existing .po files with the new i18n.pot file ● Poedit can give translation hints for similar strings
  35. 35. Demo source code: https://github.com/xitrum-framework/scala-xgettext-presentation If you use Play framework: https://github.com/georgeOsdDev/play-xgettext
  • ohtsuchi

    Jan. 18, 2016
  • superman149

    Aug. 12, 2015
  • georgeosd

    Aug. 11, 2015

This presentation explains about GNU gettext and how to internationalize Scala programs in in gettext style.

Views

Total views

1,863

On Slideshare

0

From embeds

0

Number of embeds

27

Actions

Downloads

4

Shares

0

Comments

0

Likes

3

×