https://github.com/druids/gettext
GNU Gettext for Clojure based on Easy I18N
https://github.com/druids/gettext
Last synced: over 1 year ago
JSON representation
GNU Gettext for Clojure based on Easy I18N
- Host: GitHub
- URL: https://github.com/druids/gettext
- Owner: druids
- License: mit
- Created: 2018-06-06T08:34:24.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-06T13:42:29.000Z (about 8 years ago)
- Last Synced: 2025-01-30T02:14:13.881Z (over 1 year ago)
- Language: Clojure
- Size: 10.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
gettext
=======
[GNU Gettext](https://www.gnu.org/software/gettext) for Clojure based on
[Easy i18n](https://github.com/awkay/easy-i18n).
Gettext library is just a thin wrapper around Easy i18n for ease usage.
[](https://jarkeeper.com/druids/gettext)
[](https://opensource.org/licenses/MIT)
Leiningen/Boot
--------------
To install, add the following to you project `:dependencies`:
```clojure
[druids/gettext "0.2.0"]
```
And into `:plugins`, if you want to call leiningen tasks.
Requirements
------------
Install a system dependency [GNU Gettext](https://www.gnu.org/software/gettext).
Configuration
-------------
A path for message files can be specified in `project.clj` like:
```clojure
{:gettext {:target-dir "resources/myproject/i18n"}
```
When the path is not specified following path is used: "resources/PROJECT\_NAME/i18n".
Usage
-----
Before you start a language file need to be initialized, e.g.:
```sh
lein gettext init cs ge
```
When translations are done, messages need to be merged:
```sh
lein gettext merge cs ge
```
And compiled into Java classes:
```sh
lein gettext compile cs ge
```
`gettext.core` namespace provides following functions:
- `tr` a basic translate function
- `trc` translates a string in the given context
- `trf` a basic translate function within format abilities
- `trcf` translate a message with context and arguments
- `trp` formats a string that varies based on plural forms
Examples:
```clojure
(require '[gettext.core :as gettext])
(gettext/tr "Hello") ;; Hello
(gettext/tr :de "Hello") ;; "Hallo"
(gettext/trf "Hello {0}" ["world"]) ;; "Hello world"
(gettext/trf :de "Hello {0}" ["Das Welt"]) ;; "Hallo Das Welt"
```
Notes
-----
Currently extracting messages from Clojure code is **NOT** supported. This job has to be done by a hand.