function svg_embed_manage_po_files in SVG Embed 7
Form to download and upload PO files for embedded SVG files.
Parameters
array $form: form definition
array $form_state: form state
Return value
array renderable form
1 string reference to 'svg_embed_manage_po_files'
- svg_embed_menu in ./
svg_embed.module - Implements hook_menu().
File
- ./
svg_embed.module, line 147 - SVG Embed. Provides a filter for text formats that includes and on the fly translates SVG files into text fields.
Code
function svg_embed_manage_po_files($form, $form_state) {
$strings = array();
$files = db_select('file_managed', 'f')
->fields('f', array(
'uri',
))
->condition('f.filemime', 'image/svg+xml')
->execute()
->fetchAll();
foreach ($files as $file) {
$svg = file_get_contents($file->uri);
if (!empty($svg)) {
$xml = new SimpleXMLElement($svg);
if (!empty($xml)) {
_svg_embed_extract($xml, $strings);
}
}
}
$directory = 'temporary://svg_embed';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY + FILE_MODIFY_PERMISSIONS);
$all_languages = language_list('enabled');
$languages = array_shift($all_languages);
$output = '';
foreach ($languages as $langcode => $item) {
$po = 'msgid ""' . PHP_EOL;
$po .= 'msgstr "PO-Revision-Date: 2012-03-10 14:34+0100\\nMIME-Version: 1.0\\nContent-Type: text/plain; charset=utf-8\\nContent-Transfer-Encoding: 8bit\\n\\n"' . PHP_EOL;
foreach ($strings as $string => $lng) {
$po .= PHP_EOL;
$po .= 'msgid "' . str_replace('"', '\\"', $string) . '"' . PHP_EOL;
$po .= 'msgstr "' . str_replace('"', '\\"', $lng[$langcode]) . '"' . PHP_EOL;
}
$filename = $directory . '/' . $langcode . '.po';
file_put_contents($filename, $po);
$output .= '<div>' . l($langcode, 'system/temporary/svg_embed/' . $langcode . '.po') . '</div>';
}
$form['download'] = array(
'#type' => 'fieldset',
'#title' => t('Download PO-files'),
);
$form['download']['links'] = array(
'#markup' => $output,
);
// Get all languages, except English.
drupal_static_reset('language_list');
$names = locale_language_list('name');
unset($names['en']);
if (!count($names)) {
$languages = _locale_prepare_predefined_list();
$default = key($languages);
}
else {
$languages = array(
t('Already added languages') => $names,
t('Languages not yet added') => _locale_prepare_predefined_list(),
);
$default = key($names);
}
$form['upload'] = array(
'#type' => 'fieldset',
'#title' => t('Upload PO file'),
);
$form['upload']['langcode'] = array(
'#type' => 'select',
'#title' => t('Import into'),
'#options' => $languages,
'#default_value' => $default,
'#description' => t('Choose the language you want to add strings into. If you choose a language which is not yet set up, it will be added.'),
);
$form['upload']['file'] = array(
'#type' => 'file',
'#title' => t('Language file'),
'#size' => 50,
'#description' => t('A Gettext Portable Object (<em>.po</em>) file.'),
);
$form['upload']['mode'] = array(
'#type' => 'radios',
'#title' => t('Mode'),
'#default_value' => LOCALE_IMPORT_KEEP,
'#options' => array(
LOCALE_IMPORT_OVERWRITE => t('Strings in the uploaded file replace existing ones, new ones are added. The plural format is updated.'),
LOCALE_IMPORT_KEEP => t('Existing strings and the plural format are kept, only new strings are added.'),
),
);
$form['upload']['submit'] = array(
'#type' => 'submit',
'#value' => t('Import'),
);
return $form;
}