-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
351 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
namespace Transvision; | ||
|
||
/** | ||
* Xliff class | ||
* | ||
* This class is used to manipulate translation files in XLIFF format | ||
* used in Firefox for iOS. | ||
* | ||
* @package Transvision | ||
*/ | ||
class Xliff | ||
{ | ||
/** | ||
* | ||
* Loads strings from a .xliff file | ||
* | ||
* @param string $xliff_path Path to the .xliff to load | ||
* @param string $project_name The project this string belongs to | ||
* | ||
* @return array Array of strings as [string_id => translation] | ||
*/ | ||
public static function getStrings($xliff_path, $project_name) | ||
{ | ||
$strings = []; | ||
if ($xml = simplexml_load_file($xliff_path)) { | ||
$namespaces = $xml->getDocNamespaces(); | ||
$xml->registerXPathNamespace('x', $namespaces['']); | ||
/* Get all trans-units, which include both reference (source) and | ||
/* translation (target) | ||
*/ | ||
$trans_units = $xml->xpath('//x:trans-unit'); | ||
foreach ($trans_units as $trans_unit) { | ||
/* File's name is 2 levels above in the hierarchy, stored as | ||
* 'original' attribute of the <file> element. | ||
*/ | ||
$file_node = $trans_unit->xpath('../..'); | ||
$file_name = $file_node[0]['original']; | ||
|
||
$string_id = self::generateStringID($project_name, $file_name, $trans_unit['id']); | ||
$translation = str_replace("'", "\\'", $trans_unit->target); | ||
|
||
$strings[$string_id] = $translation; | ||
} | ||
} | ||
|
||
return $strings; | ||
} | ||
|
||
/** | ||
* Generate a unique id for a string to store in Transvision. | ||
* String ID can be identical to the source string in iOS, so it's more | ||
* reliable to generate a unique ID from it. | ||
* | ||
* @param string $project_name The project this string belongs to | ||
* @param string $file_name 'original' attribute of the <file> element | ||
* @param string $string_id 'id' attribute of the <trans-unit> element | ||
* | ||
* @return string unique ID such as firefox_ios/Client/Intro.strings:1cd1dc4e | ||
*/ | ||
public static function generateStringID($project_name, $file_name, $string_id) | ||
{ | ||
return "{$project_name}/{$file_name}:" . hash('crc32', $string_id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
namespace Transvision; | ||
|
||
// Script should not be called from the Web | ||
if (php_sapi_name() != 'cli') { | ||
die("This command can only be used in CLI mode.\n"); | ||
} | ||
|
||
if (count($argv) < 2) { | ||
die("This command needs more parameters, please check tmx_xliff --help.\n"); | ||
} | ||
if (isset($argv[1])) { | ||
if (in_array($argv[1], ['-h', '--help'])) { | ||
$command_help = "tmx_xliff - Create TMX from XLIFF file\n" . | ||
"Usage: tmx_xliff [project_name]\n\n" . | ||
"Example: tmx_xliff firefox_ios\n"; | ||
die($command_help); | ||
} | ||
} | ||
|
||
include __DIR__ . '/../inc/init.php'; | ||
|
||
$project_name = $argv[1]; | ||
|
||
$supported_projects = [ | ||
'firefox_ios' => [ | ||
'file_name' => 'firefox-ios.xliff', | ||
'base_path' => SVN . 'firefox_ios', | ||
], | ||
]; | ||
|
||
if (! isset($supported_projects[$project_name])) { | ||
die("Unknown project: {$project_name}.\n"); | ||
} | ||
error_log('Extraction of strings from XLIFF file'); | ||
|
||
$base_path = $supported_projects[$project_name]['base_path']; | ||
foreach (Files::getFilenamesInFolder($base_path, ['templates', 'README']) as $locale) { | ||
$out_translation = ''; | ||
$total_strings = 0; | ||
|
||
$xliff_path = "{$base_path}/{$locale}/{$supported_projects[$project_name]['file_name']}"; | ||
if (file_exists($xliff_path)) { | ||
$strings = Xliff::getStrings($xliff_path, $project_name); | ||
$total_strings = count($strings); | ||
foreach ($strings as $string_id => $translation) { | ||
$out_translation .= "'{$string_id}' => '{$translation}', \n"; | ||
} | ||
} else { | ||
error_log("{$locale}: file is missing"); | ||
} | ||
$out_translation = "<?php\n\$tmx = [\n" . $out_translation . "];\n"; | ||
|
||
Files::fileForceContents(TMX . "{$locale}/cache_{$locale}_{$project_name}.php", $out_translation); | ||
error_log("{$locale}: {$total_strings} strings"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd"> | ||
<file original="Client/BookmarkPanel.strings" source-language="en" datatype="plaintext" target-language="it"> | ||
<header> | ||
<tool tool-id="com.apple.dt.xcode" tool-name="Xcode" tool-version="7.0" build-num="7A220"/> | ||
</header> | ||
<body> | ||
<trans-unit id="Delete"> | ||
<source>Delete</source> | ||
<target>Elimina</target> | ||
<note>Action button for deleting bookmarks in the bookmarks panel.</note> | ||
</trans-unit> | ||
<trans-unit id="Desktop Bookmarks"> | ||
<source>Desktop Bookmarks</source> | ||
<target>Segnalibri pc desktop</target> | ||
<note>The folder name for the virtual folder that contains all desktop bookmarks.</note> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
<file original="Client/ClearPrivateData.strings" source-language="en" datatype="plaintext" target-language="it"> | ||
<header> | ||
<tool tool-id="com.apple.dt.xcode" tool-name="Xcode" tool-version="7.0" build-num="7A220"/> | ||
</header> | ||
<body> | ||
<trans-unit id="Are you sure you want to clear all of your data? This will also close all open tabs."> | ||
<source>Are you sure you want to clear all of your data? This will also close all open tabs.</source> | ||
<target>Eliminare tutti i dati? Verranno anche chiuse tutte le schede aperte.</target> | ||
<note>Message shown in the dialog prompting users if they want to clear everything</note> | ||
</trans-unit> | ||
<trans-unit id="Browsing History"> | ||
<source>Browsing History</source> | ||
<target>Cronologia di navigazione</target> | ||
<note>Settings item for clearing browsing history</note> | ||
</trans-unit> | ||
<trans-unit id="Cache"> | ||
<source>Cache</source> | ||
<target>Cache</target> | ||
<note>Settings item for clearing the cache</note> | ||
</trans-unit> | ||
<trans-unit id="Cancel"> | ||
<source>Cancel</source> | ||
<target>Annulla</target> | ||
<note>Used as a button label in the dialog to cancel clear private data dialog</note> | ||
</trans-unit> | ||
<trans-unit id="Clear"> | ||
<source>Clear</source> | ||
<target>Elimina</target> | ||
<note>Used as a button label in the dialog to Clear private data dialog</note> | ||
</trans-unit> | ||
<trans-unit id="Clear Everything"> | ||
<source>Clear Everything</source> | ||
<target>Eliminazione dati</target> | ||
<note>Title of the Clear private data dialog.</note> | ||
</trans-unit> | ||
<trans-unit id="Clear Private Data"> | ||
<source>Clear Private Data</source> | ||
<target>Elimina dati personali</target> | ||
<note>Button in settings that clears private data for the selected items. | ||
Navigation title in settings.</note> | ||
</trans-unit> | ||
<trans-unit id="Cookies"> | ||
<source>Cookies</source> | ||
<target>Cookie</target> | ||
<note>Settings item for clearing cookies</note> | ||
</trans-unit> | ||
<trans-unit id="Offline Website Data"> | ||
<source>Offline Website Data</source> | ||
<target>Dati non in linea dei siti web</target> | ||
<note>Settings item for clearing website data</note> | ||
</trans-unit> | ||
<trans-unit id="Saved Logins"> | ||
<source>Saved Logins</source> | ||
<target>Accessi salvati</target> | ||
<note>Settings item for clearing passwords and login data</note> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.