source: tools/po_convertor/po_to_lang.php

Last change on this file was 3, checked in by george, 14 years ago
  • Přidáno: Převaděč mezi lang a po jazykovými soubory.
File size: 1.5 KB
Line 
1<?php
2
3$OriginalLangFileName = 'lang-en.php';
4$TranslatedFileName = 'boonex-dolphin-7-cs.po';
5$LangFileName = 'lang-cs.php';
6
7// Build dictionary
8$Dictionary = array();
9$Source = file_get_contents($OriginalLangFileName);
10$Source = explode("\n", $Source);
11foreach($Source as $Line)
12{
13 $Parts = explode('=>', $Line);
14 if(count($Parts) == 2)
15 {
16 $MsgId = substr(trim($Parts[0]), 1, -1);
17 $MsgStr = trim($Parts[1]);
18 if(substr($MsgStr, -1) == ',') $MsgStr = substr($MsgStr, 0, -1);
19 $MsgStr = substr($MsgStr, 1, -1);
20 $Dictionary[$MsgId] = $MsgStr;
21 }
22}
23
24// Load PO file
25$PoDictionary = array();
26$Source = file_get_contents($TranslatedFileName);
27$Source = explode("\n", $Source);
28foreach($Source as $Line)
29{
30 $Command = substr($Line, 0, strpos($Line, ' '));
31 $Param = substr(trim(substr($Line, strpos($Line, ' '))), 1, -1);
32 if($Command == 'msgid') $MsgId = $Param;
33 else if($Command == 'msgstr') $PoDictionary[$MsgId] = $Param;
34}
35
36// Create Lang file
37$Output = array(
38 "<?",
39 "",
40 '$LANG_INFO = array(',
41 " 'Name' => 'cs', 'Flag' => 'cz', 'Title' => 'Czech'",
42 ");",
43 "",
44 '$LANG = array(',
45);
46
47foreach($Dictionary as $Item => $Word2)
48{
49 $Word = str_replace("\'", "'", $Word2);
50 $Word = str_replace('"', '\"', $Word);
51 if(array_key_exists($Word, $PoDictionary) and ($PoDictionary[$Word] != '')) $Line = " '".$Item."' => '".$PoDictionary[$Word]."',";
52 else $Line = " '".$Item."' => '".$Word2."',";
53 $Output[] = $Line;
54}
55$Output[] = ");";
56$Output[] = "?>";
57
58file_put_contents($LangFileName, implode("\r\n", $Output));
59
60?>
Note: See TracBrowser for help on using the repository browser.