SlideShare a Scribd company logo
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 (human oriented) +
Erlang (functional)
● 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 .properties style vs gettext style)
(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 translate
printf(t("My name is %s."), myName)
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)
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 similar existing
translation to make new translation (marked
as “fuzzy” to be modified by a human later)
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
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
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."
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
gettext is quite advanced
● Allow specifying context
(one string may be translated to
different strings, depending on
context)
print(t("Hello"))
print(tc("Casual", "Hello"))
fr.po language file:
msgid "Hello"
msgstr "Bonjour"
msgctxt "Casual"
msgid "Hello"
msgstr "Salut"
gettext is quite advanced
● Allow specifying singular/plural rules
(different languages may have
different singular/plural rules)
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 %d apples"
msgstr[0] "J'ai une pomme"
msgstr[1] "J'ai %d pommes"
Singular/plural rule
Special key
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 extract i18n
strings at compile time.
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
● 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
● 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
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
key → value
data structure
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
Demo source code:
https://github.com/xitrum-framework/scala-xgettext-presentation
If you use Play framework:
https://github.com/georgeOsdDev/play-xgettext

More Related Content

PDF
Develop realtime web with Scala and Xitrum
PDF
Model with actors and implement with Akka
ODP
How to start using Scala
PDF
How to write a web framework
PPTX
Building Apis in Scala with Playframework2
PDF
Xitrum HOWTOs
PDF
Xitrum @ Scala Matsuri Tokyo 2014
PDF
Your First Scala Web Application using Play 2.1
Develop realtime web with Scala and Xitrum
Model with actors and implement with Akka
How to start using Scala
How to write a web framework
Building Apis in Scala with Playframework2
Xitrum HOWTOs
Xitrum @ Scala Matsuri Tokyo 2014
Your First Scala Web Application using Play 2.1

What's hot (20)

PDF
Scala Frameworks for Web Application 2016
PDF
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
PPTX
From Ruby to Scala
ODP
Xitrum @ Scala Conference in Japan 2013
PPTX
Actor-based concurrency and Akka Fundamentals
PDF
Web a Quebec - JS Debugging
PPTX
JS Event Loop
PDF
FITC - Here Be Dragons: Advanced JavaScript Debugging
PDF
Clojure in real life 17.10.2014
PDF
Functional Programming in Clojure
PPTX
Day 8 - jRuby
PPTX
Day 1 - Intro to Ruby
PPT
Sbt, idea and eclipse
PDF
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
PDF
Functional Programming for Busy Object Oriented Programmers
PPTX
JavaScript Basics
PDF
Ruby projects of interest for DevOps
PPTX
Scala adoption by enterprises
PDF
Skinny Framework Progress Situation
PDF
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
Scala Frameworks for Web Application 2016
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
From Ruby to Scala
Xitrum @ Scala Conference in Japan 2013
Actor-based concurrency and Akka Fundamentals
Web a Quebec - JS Debugging
JS Event Loop
FITC - Here Be Dragons: Advanced JavaScript Debugging
Clojure in real life 17.10.2014
Functional Programming in Clojure
Day 8 - jRuby
Day 1 - Intro to Ruby
Sbt, idea and eclipse
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
Functional Programming for Busy Object Oriented Programmers
JavaScript Basics
Ruby projects of interest for DevOps
Scala adoption by enterprises
Skinny Framework Progress Situation
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
Ad

Similar to I18nize Scala programs à la gettext (20)

KEY
Inside Python
ZIP
Inside Python [OSCON 2012]
PDF
I35s
PPTX
Alexander Mostovenko "Modern approach to localization in javascript with the ...
PDF
Living in a multiligual world: Internationalization for Web 2.0 Applications
PPTX
sphinx-i18n — The True Story
PDF
Living in a Multi-lingual World: Internationalization in Web and Desktop Appl...
PDF
Python-GTK
PDF
Going to Mars with Groovy Domain-Specific Languages
KEY
Translating ruby OSS
PDF
(1) cpp introducing the_cpp_programming_language
PDF
How to create a programming language
ODP
How to build your own programming language
PDF
Stupid Awesome Python Tricks
PPTX
Compilers.pptx
DOCX
How do you learn Compiler Construction.docx
PDF
Crossing the border with Qt: the i18n system
PPT
01Intro__to_compile_construction____.ppt
PPT
Python for Engineers and Architects Stud
PDF
Python Intro
Inside Python
Inside Python [OSCON 2012]
I35s
Alexander Mostovenko "Modern approach to localization in javascript with the ...
Living in a multiligual world: Internationalization for Web 2.0 Applications
sphinx-i18n — The True Story
Living in a Multi-lingual World: Internationalization in Web and Desktop Appl...
Python-GTK
Going to Mars with Groovy Domain-Specific Languages
Translating ruby OSS
(1) cpp introducing the_cpp_programming_language
How to create a programming language
How to build your own programming language
Stupid Awesome Python Tricks
Compilers.pptx
How do you learn Compiler Construction.docx
Crossing the border with Qt: the i18n system
01Intro__to_compile_construction____.ppt
Python for Engineers and Architects Stud
Python Intro
Ad

More from Ngoc Dao (16)

PDF
BIG DATA サービス と ツール
ODP
SockJS Intro
ODP
Easy distributed load test with Tsung
PPTX
Cloud Erlang
PPTX
Xitrum internals
PPT
Những lỗi bảo mật web thường gặp ở phần application
PPT
Erlang Web
PPT
Nitrogen Web Framework
PDF
スポイトができるまで
PDF
Camellia General
PPT
Nhập môn BDD
PPT
何でRuby
PDF
Sinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua Ngoc
PDF
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua G
PDF
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Ngoc
PPT
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Hung
BIG DATA サービス と ツール
SockJS Intro
Easy distributed load test with Tsung
Cloud Erlang
Xitrum internals
Những lỗi bảo mật web thường gặp ở phần application
Erlang Web
Nitrogen Web Framework
スポイトができるまで
Camellia General
Nhập môn BDD
何でRuby
Sinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua G
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Hung

Recently uploaded (20)

PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
System and Network Administration Chapter 2
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPT
Introduction Database Management System for Course Database
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
DOCX
The Five Best AI Cover Tools in 2025.docx
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
history of c programming in notes for students .pptx
PPTX
Essential Infomation Tech presentation.pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PPT
JAVA ppt tutorial basics to learn java programming
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Materi-Enum-and-Record-Data-Type (1).pptx
Softaken Excel to vCard Converter Software.pdf
System and Network Administration Chapter 2
Design an Analysis of Algorithms I-SECS-1021-03
ManageIQ - Sprint 268 Review - Slide Deck
Introduction Database Management System for Course Database
VVF-Customer-Presentation2025-Ver1.9.pptx
The Five Best AI Cover Tools in 2025.docx
Wondershare Filmora 15 Crack With Activation Key [2025
Design an Analysis of Algorithms II-SECS-1021-03
history of c programming in notes for students .pptx
Essential Infomation Tech presentation.pptx
How to Choose the Right IT Partner for Your Business in Malaysia
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Materi_Pemrograman_Komputer-Looping.pptx
JAVA ppt tutorial basics to learn java programming
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...

I18nize Scala programs à la gettext

  • 1. i18nize Scala programs à la gettext Episode 39, Wed, Aug 12, 2015 Ngoc Dao
  • 2. About the speaker ● Ngoc Dao ● Joined Atlassian since May
  • 4. ● Favorite languages: Ruby, Erlang, Scala ● My Scala style: Using Scala as if Scala = Java (performance, libs eco) + Ruby (human oriented) + Erlang (functional)
  • 5. ● Don’t know Scalaz/Haskell (yet) ↑↑↑ Struggling with monadic talks at ScalaSyd
  • 6. English is not my native language ● From Viet Nam ● 15 years in Japan ↑↑↑ i18n is important to me
  • 7. Given this program: printf("My name is %s.", myName)
  • 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. (1) Mark the strings we want to translate printf(t("My name is %s."), myName)
  • 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. 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. When strings in the program change, how to update (add, remove, modify) language files efficiently?
  • 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. 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. 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. 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. 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. gettext is quite advanced ● Allow specifying context (one string may be translated to different strings, depending on context)
  • 19. print(t("Hello")) print(tc("Casual", "Hello")) fr.po language file: msgid "Hello" msgstr "Bonjour" msgctxt "Casual" msgid "Hello" msgstr "Salut"
  • 20. gettext is quite advanced ● Allow specifying singular/plural rules (different languages may have different singular/plural rules)
  • 21. print(tn( "I have one apple", "I have %d apples", numApples )) Singular Plural Depending on this value
  • 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
  • 25. Mark and extract i18n strings
  • 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. 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. ● 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. ● 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
  • 31. Translate language template file Tool: Any text editor
  • 32. Translate language template file Tool: Any text editor Very convenient GUI editor: https://poedit.net/
  • 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. 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. Demo source code: https://github.com/xitrum-framework/scala-xgettext-presentation If you use Play framework: https://github.com/georgeOsdDev/play-xgettext