@@ -14,12 +14,13 @@ class Xliff
1414 *
1515 * Loads strings from a .xliff file
1616 *
17- * @param string $xliff_path Path to the .xliff to load
18- * @param string $project_name The project this string belongs to
17+ * @param string $xliff_path Path to the .xliff to load
18+ * @param string $project_name The project this string belongs to
19+ * @param boolean $reference_locale If the current file belongs to the reference locale
1920 *
2021 * @return array Array of strings as [string_id => translation]
2122 */
22- public static function getStrings ($ xliff_path , $ project_name )
23+ public static function getStrings ($ xliff_path , $ project_name, $ reference_locale = false )
2324 {
2425 $ strings = [];
2526 if ($ xml = simplexml_load_file ($ xliff_path )) {
@@ -36,7 +37,10 @@ public static function getStrings($xliff_path, $project_name)
3637 $ file_orig = $ file_node [0 ]['original ' ];
3738
3839 $ string_id = self ::generateStringID ($ project_name , $ file_name , $ file_orig , $ trans_unit ['id ' ]);
39- $ translation = str_replace ("' " , "\\' " , $ trans_unit ->target );
40+ // If it's the reference locale, we use the source instead of the target
41+ $ translation = $ reference_locale
42+ ? str_replace ("' " , "\\' " , $ trans_unit ->source )
43+ : str_replace ("' " , "\\' " , $ trans_unit ->target );
4044
4145 $ strings [$ string_id ] = $ translation ;
4246 }
0 commit comments