where and how to keep alternate languages is unclear to me.
Under “resources/locales/” + directory name of your translation e.g.
See: Internationalization & Localization - 4.x
Is localization something that depends on some external, standardized translation library?
Translation files (".po" and “.pot”) are textfiles (You can open it with any text editor) in
the so called “GetText portable object”-Format. That is a standard format - not standard library.
Some basic information about GetText portable objects copy + paste from
GetText Portable Object (PO) files are the industry standard for multilingual websites in PHP.
POT – Portable Object Template. This is the file that you get when you extract texts from the application. Normally, you send this file to your translators.
PO – Portable Object. This is the file that you receive back from the translators. It’s a text file that includes the original texts and the translations.
MO – Machine Object. The MO file includes the exact same contents as PO file. The two files differ in their format. While a PO file is a text file and is easy for humans to read, MO files are compiled and are easy for computers to read. Your web server will use the MO file to display the translations.
PO and POT files are essentially the same. The difference is in the intended use. This is why the two files have different extensions (.pot versus .po).
A tool that scans your PHP source will produce a .pot file. This file includes only the original texts, which need translation.
Keep in mind: that type of tool does CakePHP already have: I18N Tool - 4.x
Or is localization simply a collection of flat documents
It is a collection of text documents in a folder structure - see above.
…I create and maintain on my own
Yes - no one knows your application better than you
Just try it out like this:
Take a view of your application and replace some string in the HTML Code with e.g.
<h1><?= __("Hinweis") ?></h1>
Reload the view in the Browser: you will see the german word “Hinweis”
Now run “bin/cake i18n extract” See: I18N Tool - 4.x
A file is generated under “resources/locales/default.pot.” - in this simple case it will contain something like this:
# LANGUAGE translation of CakePHP Application
# Copyright YEAR NAME <EMAIL@ADDRESS>
"Project-Id-Version: PROJECT VERSION\n"
"POT-Creation-Date: 2020-04-18 18:46+0000\n"
"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n"
"Last-Translator: NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"
"Content-Type: text/plain; charset=utf-8\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
Now create a folder unter “resources/locales/en/” and copy the “default.pot”
into that folder and rename it to “default.po”.
Open this new file and add the english word for “Hinweis” behind the “msgstr”-Key:
Go to the “config/app.php” and set ‘defaultLocale’ => ‘en’ or ‘defaultLocale’ => env(‘APP_DEFAULT_LOCALE’, ‘en’)
Reload your Page/View - You should see the word “Notice” now.
This was a quick run through to try and understand.
You can also take some of Cakes translation files from here localized/resources/locales at master · cakephp/localized · GitHub
to translate the standard / default messages from the Cake framework for your language.