Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exportable messages #1

Open
drm opened this issue Oct 5, 2016 · 0 comments
Open

Exportable messages #1

drm opened this issue Oct 5, 2016 · 0 comments

Comments

@drm
Copy link
Contributor

drm commented Oct 5, 2016

$pdo = new PDO('mysql:host=mysql;dbname=conc053', 'dev');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->query('SET NAMES utf8;');
$q = sprintf('SELECT message, domain, locale, translation FROM message INNER JOIN message_translation ON message.id=message_id WHERE message IN(%s)', join(',', array_map([$pdo, 'quote'], $names)));

$group = [];
foreach ($pdo->query($q)->fetchAll(\PDO::FETCH_ASSOC) as $row) {
    if (!isset($group[$row['domain']])) {
        $group[$row['domain']] = [];
    }
    if (!isset($group[$row['domain']][$row['locale']])) {
        $group[$row['domain']][$row['locale']] = [];
    }
    $group[$row['domain']][$row['locale']][$row['message']] = $row['translation'];
}

chdir("exported-messages");
foreach ($group as $domain => $locales) {
    foreach ($locales as $locale => $messages) {
        $filename = sprintf('%s.%s.yml', $domain, $locale);
        file_put_contents($filename, Yaml::dump($messages));
        printf("%s written\n", $filename);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant