Skip to content

Instantly share code, notes, and snippets.

@tmilos

tmilos/arabic.php

Created Nov 25, 2015
Embed
What would you like to do?
Arabic translation dummy generator
<?php
$fileTemplate = __DIR__.'/../../app/Resources/translations/messages.%s.xliff';
$fromLocale = 'en';
$toLocale = 'ar';
$sourceFile = sprintf($fileTemplate, $fromLocale);
$targetFile = sprintf($fileTemplate, $toLocale);
$stringLetters = <<<EOT
ض
ص
ث
ق
ف
غ
ع
ه
خ
ح
ج
د
ش
س
ي
ب
ل
ا
ت
ن
م
ك
ط
ئ
ء
ؤ
ر
لا
ى
ة
و
ز
ظ
EOT;
$arrLetters = explode("\n", str_replace("\r", '', $stringLetters));
$maxLettersIndex = count($arrLetters)-1;
$xliff = new SimpleXMLElement(file_get_contents($sourceFile));
var_dump($xliff->file->body->{'trans-unit'}->count());
foreach ($xliff->file->body->{'trans-unit'} as $transUnit) {
$txt = (string)$transUnit->target;
$len = strlen($txt);
$spaceCount = substr_count($txt, ' ');
$spaceIndex = $spaceCount ? $len / $spaceCount : 0;
$content = '';
for ($i=0; $i<$len; $i++) {
if ($spaceCount > 0 && ($i % $spaceIndex == 0)) {
$content .= ' ';
$hasSpace = false;
} else {
$index = mt_rand(0, $maxLettersIndex);
$char = $arrLetters[$index];
$content .= $char;
}
}
$transUnit->target = $content;
}
$xliff->asXML($targetFile);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment