The idea of Yesod focuses on type safety in all aspects. This is covering type safe urls, type safe APIs and of course type safe translation messages. Hence, the idea behind Yesod is to focus on single phrases. It is not optimized for longer text with multiple breaks. Unfortunately Yesods file format for messages (.msg files) does not support multiline messages.
By enabling the Yesod project nature for your translation project Translatebox will always warn the translator when a break inside a phrase is used and refuse to accept the changes if pushed to Translatebox.
In comparison to other web frameworks (and several default translation solutions) Yesod does not support all kind of keys for translations. A key has always to begin with a capital character. Furthermore no special character and spaces are allowed. The reason for this is again type-safety. Yesod uses keys as type classes under the hood (using TemplateHaskell). Due to this limitation several key strategies for translations are invalid, for instance "this.is.a.translation.key" or "this is some text used as key".
Translatebox supports the default approach of Yesod but as well widens the compatibility a bit further. The mentioned keys can be used without problems inside the Translatebox Platform. If they get fetched or are downloaded, the keys are transformed into valid type class names for Haskell. Let's have a look at the following examples:
The key "this.is.a.translation.key" will become ThisIsATranslationKey and can be used as a MsgThisIsATranslationKey
in Handler or template code. The key "this is some text used as key" will become ThisIsSomeTextUsedAsKey and can be used as a MsgThisIsSomeTextUsedAsKey
in Handler or template code.
Yesod message files are usually located in the i18n folder of the project. At least this is the approach taken when setting up a new Yesod project using the stack templates. Besides this, the location of your files within your project can very. There is no special requirement for the location of the files.
The translation files end with the ending .msg and contain a (optionally parametrized) key/value list of translations. Each line represents one phrase (or in our case Translate Term). A sample file could look like this:
ThisIsASimpleTranslateKey: This is the translation of the key
ThisIsAKeyWithParams count@Int name@Text: This is a translation with #{show count} and #{name}