Example #1
0
 /**
  * Save translated data the user customized on the interface
  *
  * @param string $plugin   The plugin name
  * @param string $language The language tag
  * @param array  $data     The translations to save
  */
 public static function saveUserTranslations($plugin, $language, $data)
 {
     $lang = new self($plugin, $language);
     $file = $lang->getTranslatedFile();
     $lines = array();
     foreach ($data as $key => $value) {
         if (!is_array($value)) {
             $lines[] = $key . ' = "' . addcslashes($value, '"') . '"';
         } else {
             foreach ($value as $multiplier => $val) {
                 $lines[] = $key . '[' . $multiplier . '] = "' . addcslashes($val, '"') . '"';
             }
         }
     }
     $content = implode(PHP_EOL, $lines);
     $dir = dirname($file);
     if (!is_dir($dir)) {
         mkdir($dir, 0755, true);
     }
     file_put_contents($file, $content);
     touch($file, time() + 3);
 }