* Drush (< 9) integration for the drush_language module.
*/
useDrupal\drush_language\Drush8Io;
/**
* Implements hook_drush_command().
*
* @See drush_parse_command() for a list of recognized keys.
*/
functiondrush_language_drush_command(){
$items=[];
$items['language-add']=[
'description'=>'Add and import a new language definition',
'arguments'=>[
'langcodes'=>'The langcodes of the languages for which a definition will be added.',
],
'aliases'=>['langadd'],
];
$items['language-default']=[
'description'=>'Assign an enabled language as default',
'arguments'=>[
'langcode'=>'The langcode of the language which will be set as the default language.',
],
'aliases'=>['langdef'],
];
$items['language-import-translations']=[
'description'=>'Import a single .po file',
'arguments'=>[
'.po file(s)'=>'Path to one or more .po files to import. If omitted, $settings[\'custom_translations_directory\'] must be set and all .po files from that directory will be taken. If langcode (overridable), project and version can be deduced from the filename, they will be stored in the translation database.',
],
'examples'=>[
'Import all custom translations from the directory defined in $settings[\'custom_translations_directory\'].'=>'drush langimp',
'Import single file with explicit langcode'=>'drush langimp --langcode=ru file.po',
'Import not-customized (e.g. module) translations, without replacing custom translations, with auto langcode (these are the recognized patterns)'=>'drush langimp --langcode=eo --no-set-customized --no-replace-customized de.po foomodule.fr.po barmodule-8.x-2.2-rc1.es.po',
],
'options'=>[
'langcode'=>[
'description'=>'Language code to be imported. If not given, extracted from file name.',
'value'=>'optional',
],
'replace-customized'=>[
'description'=>'Replace existing customized translations. Defaults to true.',
'value'=>'optional',
],
'replace-not-customized'=>[
'description'=>'Replace existing not-customized translations. Defaults to true.',
'value'=>'optional',
],
'set-customized'=>[
'description'=>'Set all existing translations as being customized. Defaults to true.',
'value'=>'optional',
],
'autocreate-language'=>[
'description'=>'Autocreate any imported language if it does not yet exist. Defaults to true.',
'value'=>'optional',
],
],
'aliases'=>['langimp','language-import'],
];
$items['language-export-translations']=[
'description'=>'Export string of a language as one or more .po files',
'examples'=>[
'Export all custom translations into the directory defined in $settings[\'custom_translations_directory\'].'=>'drush langexp',
'Export all german translated strings'=>'drush langexp --langcodes=de --status=customized,not-customized --file=all-de.po',
'Export untranslated strings from all languages to current dir'=>'drush langexp --status=untranslated --file=./todo-%langcode.po',
],
'options'=>[
'statuses'=>[
'description'=>"The statuses to export, defaults to 'customized'\nThis can be a comma-separated list of 'customized', 'not-customized', 'not-translated', or (as abbreviation) 'all'.",
'value'=>'optional',
],
'langcodes'=>[
'description'=>'The language codes to export, comma-separated. Defaults to all enabled languages.',
'value'=>'optional',
],
'file'=>[
'description'=>'The target file pattern. You can use %langcode as placeholder. Defaults to "%language.po". If the path is relative and does not start with ".", $settings[\'custom_translations_directory\'] must be defined and the path is relative to that directory.',
'value'=>'optional',
],
'force'=>[
'description'=>'Write file even if no translations. Defaults to true.',
'value'=>'optional',
],
],
'aliases'=>['langexp','language-export'],
];
return$items;
}
/**
* Add a language.
*/
functiondrush_drush_language_language_add(){
$args=func_get_args();
if(count($args)==0){
returndrush_set_error('DRUSH_LANGUAGE',dt('Please provide one or more language codes as arguments.'));
$io->error($t('Can not export, relative path given and no $settings[\'custom_translations_directory\'] defined. You can instead use an absolute filename or one starting with "./".'));
All of the above assertions can be prefixed with `nullOr*()` to run the
assertion only if it the value is not `null`:
```php
Assert::nullOrString($middleName,'The middle name must be a string or null. Got: %s');
```
### Extending Assert
The `Assert` class comes with a few methods, which can be overridden to change the class behaviour. You can also extend it to
add your own assertions.
#### Overriding methods
Overriding the following methods in your assertion class allows you to change the behaviour of the assertions:
*`public static function __callStatic($name, $arguments)`
* This method is used to 'create' the `nullOr` and `all` versions of the assertions.
*`protected static function valueToString($value)`
* This method is used for error messages, to convert the value to a string value for displaying. You could use this for representing a value object with a `__toString` method for example.
*`protected static function typeToString($value)`
* This method is used for error messages, to convert the a value to a string representing its type.
*`protected static function strlen($value)`
* This method is used to calculate string length for relevant methods, using the `mb_strlen` if available and useful.
*`protected static function reportInvalidArgument($message)`
* This method is called when an assertion fails, with the specified error message. Here you can throw your own exception, or log something.
## Static analysis support
Where applicable, assertion functions are annotated to support Psalm's
* @expectedExceptionMessage The absolute path "/webmozart/puli/css/style.css" cannot be made relative to the relative path "webmozart/puli". You should provide an absolute base path instead.
* @expectedExceptionMessage The absolute path "/webmozart/puli/css/style.css" cannot be made relative to the relative path "". You should provide an absolute base path instead.