osama7901 osama7901 - 1 month ago 9
PHP Question

Silverstripe i18n collecting translations in the templates only creates en.yaml?

I am building a site that uses ar and en languages, and according to the silverstripe docs here, I did the text collection process and went successful. but only one en.yaml file is created in the lang folder in my current theme. there should be another ar.yaml file!.

here's my _config.php file:

<?php

global $project;
$project = 'mysite';

FulltextSearchable::enable();

global $databaseConfig;
$databaseConfig = array(
'type' => 'MySQLDatabase',
'server' => 'localhost',
'username' => 'dbuser',
'password' => '123',
'database' => 'cont_learning_2',
'path' => ''
);

// Set the site locale
i18n::set_locale('ar_EG');

Director::set_environment_type('dev');

if(!Director::isDev()) {
// log errors and warnings
SS_Log::add_writer(new SS_LogFileWriter('../silverstripe-errors-warnings.log'), SS_Log::WARN, '<=');

// or just errors
SS_Log::add_writer(new SS_LogFileWriter('../silverstripe-errors.log'), SS_Log::ERR);

// or notices (e.g. for Deprecation Notifications)
SS_Log::add_writer(new SS_LogFileWriter('../silverstripe-errors-notices.log'), SS_Log::NOTICE);
}

Security::setDefaultAdmin('admin','admin');



// multi-language configuration - translatable module
Translatable::set_default_locale('ar_EG');
Translatable::set_allowed_locales(array(
'ar_EG',
'en_US',
));
SiteTree::add_extension('Translatable');

wmk wmk
Answer

Using https://github.com/Zauberfisch/silverstripe-better-i18n you are able to create and update different languages in one task. You can install it with composer as a development-only requirement.

I run it like

http://localhost/dev/tasks/BetterI18nTextCollectorTask?module=mysite,themes/my-theme&targetlocale=de,en

to create german and english yml files in mysite and themes/my-theme.

It will create a bunch of items prefixed with double underscore (as pseudo comments) and also the default keys for your database fields.

Comments