#!/usr/bin/env php $urn) { $lower = str_replace([':', '-'], '_', strtolower($name)); if (!array_key_exists('attribute_' . $lower, $defs)) { $defs['attribute_' . $lower] = []; } if (!array_key_exists('attribute_' . $lower, $trans)) { $trans['attribute_' . $lower] = []; } if (array_key_exists('no', $trans['attribute_' . $lower])) { // fix the locale code $trans['attribute_' . $lower]['nb'] = $trans['attribute_' . $lower]['no']; unset($trans['attribute_' . $lower]['no']); } $names = [$name, $urn, $urns[$urn]]; if (array_key_exists($urn, $schac)) { $names[] = $schac[$urn]; } $attributes[$name] = [ 'names' => $names, 'translations' => array_merge( [ 'en' => $defs['attribute_' . $lower]['en'], ], $trans['attribute_' . $lower], ), ]; } // process other sets of attributes foreach (['facebook', 'linkedin', 'openid', 'twitter', 'windowslive'] as $set) { include_once($base . 'attributemap/' . $set . '2name.php'); foreach ($attributemap as $alias => $attr) { if (array_key_exists($attr, $attributes)) { $attributes[$attr]['names'][] = $alias; } } } // build the dictionaries per language foreach (array_keys($languages) as $language) { $strings = new Gettext\Translations(); // load existing translations in the PO files $strings->addFromPoFile($base . 'locales/' . $language . "/LC_MESSAGES/attributes.po"); foreach ($attributes as $attribute) { foreach ($attribute['names'] as $name) { if (empty($name)) { continue; } $translation = new Gettext\Translation('', $name); if ( array_key_exists($language, $attribute['translations']) && !is_null($attribute['translations'][$language]) ) { $t = $strings->find($translation); if ($t) { if ($t->getOriginal() === $t->getTranslation()) { $t->setTranslation($attribute['translations'][$language]); $translation = $t; } } } if (!is_null($attribute['translations']['en']) && $language !== 'en') { $translation->addComment('English string: ' . $attribute['translations']['en']); } $strings[] = $translation; } } foreach ($strings as $entry) { if ($entry->getTranslation() === '') { // ensure that all entries contain a translation string $entry->setTranslation($entry->getOriginal()); } } // remove headers that only cause unnecessary changes in our commits $strings->deleteHeader('POT-Creation-Date'); $strings->deleteHeader('PO-Revision-Date'); $strings->setLanguage($language); echo "Saving translations to " . $base . "locales/" . $language . "/LC_MESSAGES/attributes.po\n"; Gettext\Generators\Po::toFile($strings, $base . 'locales/' . $language . '/LC_MESSAGES/attributes.po'); }