Skip to content

Instantly share code, notes, and snippets.

@halfdan
Created August 16, 2013 20:23
Show Gist options
  • Save halfdan/6253228 to your computer and use it in GitHub Desktop.
Save halfdan/6253228 to your computer and use it in GitHub Desktop.
Conversion script for Piwik translation array to JSON
<?php
$nest = true;
foreach (glob("lang/*.php") as $filename) {
echo sprintf("Converting %s\n", basename($filename));
require_once "lang/".basename($filename);
$basename = explode(".", basename($filename));
if($nest) {
$nested = array();
foreach($translations as $key => $value) {
list($plugin, $nkey) = explode("_", $key, 2);
$nested[$plugin][$nkey] = $value;
}
$translations = $nested;
}
$data = json_encode($translations, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
$newFile = sprintf("lang/%s.json", $basename[0]);
file_put_contents($newFile, $data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment