Storages for translation strings¶
Koded offers two different catalogs out of the box
GettextCatalog
DefaultCatalog
Both are doing the same thing and the difference is how the translated strings are stored.
Which one to use?
GettextCatalog
for projects with lots of languages (therefore lots of translators).DefaultCatalog
for simple projects or relatively small amount of strings or languages support.
There is no right or wrong choice, just pick one that you think is easy to work with or is suitable for your project.
DefaultCatalog¶
The strings are stored in the /locale/
application directory in a .php
file with a locale name
locale
├── de_DE.php
├── en_US.php
└── mk_MK.php
etc.
The structure for the en_US.php
translation file is
<?php
return [
'language' => 'English',
'messages' => [
]
];
Examples¶
# locale/en_US.php
<?php
return [
'language' => 'English',
'messages' => [
'original string' => 'translated string',
'pagination.pages' => 'page {0} of {1}',
]
];
# somewhere in your code
__('original string') // outputs: "translated string"
__('pagination.pages', [1, 42]) // outputs: "page 1 of 42"
GettextCatalog¶
This catalog requires the gettext
PHP extension and uses the excellent translation functionality provided by it.
The strings are stored in .po/.mo
files within a proper directory structure:
locale
└── en_US
└── LC_MESSAGES
├── messages.mo
└── messages.po
etc.