# \[ANN\] SimpleTranslations package

**URL:** <https://discourse.julialang.org/t/ann-simpletranslations-package/39842>\
**Category:** Community\
**Tags:** package, announcement\
**Created:** [May 20, 2020, 4:19pm UTC](https://discourse.julialang.org/t/ann-simpletranslations-package/39842 "2020-05-20T16:19:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmolina](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmolina/32/5246_2.png) [@dmolina](https://discourse.julialang.org/u/dmolina)\
**Post date:** [May 20, 2020, 4:19pm UTC](https://discourse.julialang.org/t/ann-simpletranslations-package/39842/1 "2020-05-20T16:19:25Z")

</div>

[SimpleTranslations](https://github.com/dmolina/SimpleTranslations.jl) is a simple way to translate the different messages to users  
(including the possible error messages) to different languages.

This package raised as a need utility to translate several error messages to users in different languages without including many dependencies. I hope you could consider it useful.

## Usage

The term _Simple_ means that the package is not oriented to be a complex system,  
but as a simple and easy to use way to translate messages. For instance, in this  
packages all the configuration is in a simple file, _mesages.ini_, as:

```julia-auto
[config]
languages=es,fr,en
default=en

[en]
hi=Hi everybody
...

[es]
hi=Hola a todos
...

[fr]
hi=Bonjour
...

```

Then, we can load the messages in the different languages:

```julia-auto
using SimpleTranslations

# Get the messages from a file
messages = loadmsgs("messages.ini")
# Show the message in the default language
println(get_msg(messages, "hi")) # Return "Hi everybody"
# Change the language to spanish 
set_language!(messages, "es")
println(get_msg(messages, "hi")) # Return "Hola a todos"

```

Also, when only one file is used, it can be simpler:

```julia-auto
using SimpleTranslations

# Get the messages from a file
loadmsgs!("messages.ini")
# Show the message in the default language
println(get_msg("hi")) # Return "Hi everybody"
# Change the language to spanish 
set_language!("es")
println(get_msg("hi")) # Return "Hola a todos"

```

## Advantages

The advantages of using this package is:

- All the messages are easily changed in a external fine, without changing the  
source code.

- Add an additional language is very easy, only add content in the file in text  
mode.

- An optional _strict\_mode_, in which when the file is loaded, it is checked  
that all messages are translated to all supported languages.

## Relative Packages

In order to show the values of variables in the messages, it is recommended to  
use the package [Formatting.jl](https://github.com/JuliaIO/Formatting.jl).

An more powerful and standard way to translate messages is through  
[Gettext](https://github.com/Julia-i18n/Gettext.jl) that works on the standards  
.po and .mo files. However, this package has several advantages:

- Gettext.jl currently depends on PyCall, so it implies to include many dependencies.

- _xgettext_ is a great tool to extract messages from source code, but it is actually not working in Julia.

- In _SimpleTranslations_ the input format is simpler.

- _SimpleTranslations_, at difference of _Gettext_, allows a strict mode, in which the is throw an error if an error message is not translated to a language.

For more information, you can see the [Github Repository](https://github.com/dmolina/SimpleTranslations.jl) and the [Documentation](https://dmolina.github.io/SimpleTranslations.jl/dev/tutorial/).
