Diet: Dictionary
With the dictionary module you can translate your app into any language using the echo()
function and the dictionary
table inside your mysql database.
Install
If you have diet
then it's already installed.
npm install diet-dictionary
Prerequsitions
- Make sure you have
mysql
installed - Make sure you have
diet
installed - Make sure you have correct
mysql configuration
when you initialize yourdiet
app - Create a
dictionary
table inside your mysql database
dictionary
table
Example If you want to support more languages just create a new column
for it and restart the server.
English | Hungarian | Spanish |
---|---|---|
Hello | Szia | Hola |
How are you? | Hogy vagy? | ¿Cómo estás? |
Example Backend Usage
var app = options; app;
Example Usage in HTML
{{-echo @title}}<!-- outputs: "Üdv Világ" --> {{-echo @title}} <!-- outputs: "Üdv Világ" --> {{-echo 'How are you?'}} <!-- outputs: "Hogy vagy?" -->
Example Usage in Client Side JS
You will need to include the dictionary.js
files which is autogenerated for you in:
/your_app/resources/scripts/dictionary.js
This is how it looks like:
Piece of Cake <!-- Just Include the Auto Generated dictionary.js file --> <!-- Then start using the echo function to translate things --> diet is awesome
You can see what's the current language in window.language
set within dictionary.js
. You can change the language by changing response.head.language
in html and response.cookies.set('language', 'yourLanguage')
for client side javacsript.