I created a file (de.php) next to the en.php in core/Cockpit/i18n/
I uncomment the common block and was thinking that I can choose the language now in the interface on my account page, but I still can only choose English.
If found this snippet here:
protected function getLanguages() {
$languages = [["i18n" => 'en', "language"=> 'English']];
foreach ($this->app->helper("fs")->ls('*.php', 'custom:i18n') as $file) {
$lang = include($file->getRealPath());
$i18n = $file->getBasename('.php');
$language = isset($lang['@meta']['language']) ? $lang['@meta']['language'] : $i18n;
$languages[] = ["i18n" => $i18n, "language"=> $language];
}
return $languages;
}
in core/Auth/Controller/Accounts.php but I don't understand the logic.
even if I change the $languages to this
$languages = [
["i18n" => 'en', "language"=> 'English'],
["i18n" => 'de', "language"=> 'Deutsch'],
];
I have can select in the view the german language, but it doesn't do anything, after reloading the page it's still english.
Are you on the legacy version or next branch?
I'm not sure, I've clicked on the website on stable and then I was redirected to GitHub where I installed 0.13.0
And I also tried to add a config.php in the custom directory with this content:
<?php
return [
'i18n' => 'de'
];
But that did not help, it still in english.
BTW: is that okay, that there is no closing ?> tag in both config.php and de.php?
OK you are using the legacy version. The next branch is basically a complete rewrite of the codebase and makes this particular functionality you're trying to achieve far more trivial. In the next codebase, you would just supply something resembling the following in your config.php (or config.yaml, depending on your preference - using yaml syntax in that case of course):
return [
"languages" => [
"enGB"=>"English (UK)",
"enAU"=>"English (Australia)",
"ptBR"=>"Portuguese (Brazil)",
"esMX"=>"Spanish (Mexico)",
"frFR"=>"French (France)",
"itIT"=>"Italian (Italy)",
"deDE"=>"German (Germany)",
"esES"=>"Spanish (Spain)",
"ruRU"=>"Russian (Russia)",
"plPL"=>"Polish (Poland)",
"csCZ"=>"Czech (Czech Republic)",
"koKR"=>"Korean (Korea)",
"jaJP"=>"Japanese (Japan)",
"zhTW"=>"Traditional Chinese (Taiwan)",
"zhCN"=>"Simplified Chinese (China)",
"nlNL"=>"Dutch (Netherlands)"
]
];
I don't know how to get this working in the old version, but I would suggest updating to the next branch anyway as it is plenty stable and has a lot of useful new features.
Okay I switched to next now and used your snippet, now I get translations for the collections.
But my question was how I get a different language for the webinterface of Cockpit itself.
I found this repository: https://github.com/COCOPi/cockpit-i18n
But it doesn't work just to copy these files into custom/i18n
So in next the important code is this here in modules/Cockpit/Controller/Accounts.php I think:
protected function getLanguages() {
$languages = [];
foreach ($this->app->helper("fs")->ls('*.php', '#config:cockpit/i18n') as $file) {
$lang = include($file->getRealPath());
$i18n = $file->getBasename('.php');
$language = isset($lang['@meta']['language']) ? $lang['@meta']['language'] : $i18n;
$languages[] = ["i18n" => $i18n, "language"=> $language];
}
if (!count($languages)) {
$languages[] = ["i18n" => 'en', "language" => 'English'];
}
return $languages;
}
The lookup happens here $this->app->helper("fs")->ls('*.php', '#config:cockpit/i18n') but I don't understand that line, which directory is used for lookup, all php files of which directory and what does #config:cockpit/i18n mean?
Okay I got it, I moved now the de.php file from the repo to /config/cockpit/i18n But the UI is a bit broken after switching to german I can't switch back, also for new accounts I only can choose german.
The repo also does not contain the english version, my idea was to add the english one to get the select box working again (let me choose between english and german)
EDIT: I'm sorry, I JUST realized I totally misunderstood your question. I get it now. You want to translate Cockpit, not your data. Hah. Sorry, I am not sure how to do that and can't be much help.
The config snippet I gave you should have done what you're trying to do. You shouldn't have to do anything hacky with PHP - this is handled in the config now (assuming you are in fact on the next branch).
You're trying to customize this menu, right?

To verify you are on the next branch, check the cockpit settings and you should see something like:

You still don't understand me: I'm not trying to add languages for the collections or any user related, I want to change the language of cockpit itself, for the accounts!
What you showed me in your screenshot it already solved and done.
I got it working, so you either use english locale for cockpit or if you want to use a different language for the/each accounts, you need to add your locale from the repo and you also need to add the english one (otherwise you can't switch back), the english one you can grab from the master brancht: https://github.com/COCOPi/cockpit/blob/8a1286b4161934454ace70d1c4fd82525ff02f03/modules/core/Cockpit/i18n/en.php
The files needs to be uploaded to ROOT/config/cockpit/i18n.
I wonder if there are some docs for next, I would like to add that if it's not there yet.
Yeah I realized after I posted that - sorry for the confusion. I understand that @aheinze is currently working on docs for the new version and hopes to release them in the coming weeks.
@timaschew sorry for the late reply. you need to put the language file into config/cockpit/i18n (you need to create the folders)
Update:
I see you figured it out already 馃憤馃徎
Nothing to sorry ;)
So for next it's a different direcotry,
next: config/cockpit/i18n
legacy: custom/i18n
But there is also another difference: for next you need to copy the english locale to the i18n directory as well, for legacy you don't need to do that.
ok, I'll check that. Thanks!
Most helpful comment
You still don't understand me: I'm not trying to add languages for the collections or any user related, I want to change the language of cockpit itself, for the accounts!
What you showed me in your screenshot it already solved and done.
I got it working, so you either use english locale for cockpit or if you want to use a different language for the/each accounts, you need to add your locale from the repo and you also need to add the english one (otherwise you can't switch back), the english one you can grab from the master brancht: https://github.com/COCOPi/cockpit/blob/8a1286b4161934454ace70d1c4fd82525ff02f03/modules/core/Cockpit/i18n/en.php
The files needs to be uploaded to
ROOT/config/cockpit/i18n.I wonder if there are some docs for next, I would like to add that if it's not there yet.