https://github.com/chrbauer/gettext-th
compile time localization of haskell programs
https://github.com/chrbauer/gettext-th
Last synced: 4 months ago
JSON representation
compile time localization of haskell programs
- Host: GitHub
- URL: https://github.com/chrbauer/gettext-th
- Owner: chrbauer
- Created: 2022-08-07T11:15:21.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-12-31T11:26:03.000Z (over 3 years ago)
- Last Synced: 2025-12-08T01:13:47.259Z (6 months ago)
- Language: Nix
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# gettext-th
The [gettext](https://www.gnu.org/software/gettext/) project provides a library and tools for internationalization and localization of software. Haskell has already support for gettext. It is possible either to use the C-library with FFI ([hgettext](https://hackage.haskell.org/package/hgettext)) or to use a pure Haskell implementation ([haskell-gettext](https://hackage.haskell.org/package/haskell-gettext-0.1.2.0)).
With gettext the executables and the translations are separated and the language strings are looked up at runtime. The [loadCatalog](https://hackage.haskell.org/package/haskell-gettext-0.1.2.0/docs/Data-Gettext.html) of gettext-haskell has to read the translations at runtime with IO.
This is difficult if you transpile your haskell code to javascript, which runs in a browser. To close this gap gettext-th moves the lookup of messages to compile time. A similar approach was taken for [angular-i18n](https://angular.io/guide/i18n-overview) for performance reasons.
This of course has some drawbacks (less flexible and one program per language) and some benefits (simple and performant).
Theoretically gettext-th could also choose between runtime and compile time lookups.
# Warning
gettext-th will use IO at compile time and will write a file.
# How to use it
See for an example in example/hello.
To use gettext-th in your app use it and compile it. It will fail, but it will create the file po/messages_.pot.
Run in the po folder:
```sh
msginit
msgfmt en_US.po
```
With that the program compiles. And you can update en_US.po again.
Now copy en_US.po to de_DE.po, translate the messages and run `msgfmt de_DE.po`.
If you recompile (maybe run cabal clean first) the output of your app is in german.
If you have messages in multiple files, gettext-th writes for each of them a pot file. Use msgcat to merge them.