您在這裡

檢查Drupal的.po翻譯文件中缺少哪些詞的PHP程序

James Qi 在 2013年8月29日 - 14:32 發表

  最近在處理一些小問題的時候積累了一些小程序來解決,現在記錄下來以備後用。

  Drupal多語言網站是通過.po的翻譯文件來導入翻譯數據的,有一批國家/地區名稱需要導入,而以前的.po文件中包括了一部分,隻需要找出并添加新的詞,這個過程人工來核對比較麻煩,就用了下面這段程序:

<?php
// check what countries should be added to translation file
// james qi 2013-8-14 祁勁松
$array_country=array(//總的需要導入翻譯的詞列表
"Andorra",
"United Arab Emirates",
"Afghanistan",
"Antigua and Barbuda",
"Anguilla",
"Albania",
"Armenia",
"Angola",
"Antarctica",
"Argentina",
"American Samoa",
"Austria",
"Australia",
"Aruba",
"Aland Islands",
"Azerbaijan",
"Bosnia and Herzegovina",
"Barbados",
"Bangladesh",
"Belgium",
"Burkina Faso",
"Bulgaria",
"Bahrain",
"Burundi",
"Benin",
"Saint Barthelemy",
"Bermuda",
"Brunei",
"Bolivia",
"Bonaire, Saint Eustatius and Saba ",
"Brazil",
"Bahamas",
"Bhutan",
"Bouvet Island",
"Botswana",
"Belarus",
"Belize",
"Canada",
"Cocos Islands",
"Democratic Republic of the Congo",
"Central African Republic",
"Republic of the Congo",
"Switzerland",
"Ivory Coast",
"Cook Islands",
"Chile",
"Cameroon",
"China",
"Colombia",
"Costa Rica",
"Cuba",
"Cape Verde",
"Curacao",
"Christmas Island",
"Cyprus",
"Czech Republic",
"Germany",
"Djibouti",
"Denmark",
"Dominica",
"Dominican Republic",
"Algeria",
"Ecuador",
"Estonia",
"Egypt",
"Western Sahara",
"Eritrea",
"Spain",
"Ethiopia",
"Finland",
"Fiji",
"Falkland Islands",
"Micronesia",
"Faroe Islands",
"France",
"Gabon",
"United Kingdom",
"Grenada",
"Georgia",
"French Guiana",
"Guernsey",
"Ghana",
"Gibraltar",
"Greenland",
"Gambia",
"Guinea",
"Guadeloupe",
"Equatorial Guinea",
"Greece",
"South Georgia and the South Sandwich Islands",
"Guatemala",
"Guam",
"Guinea-Bissau",
"Guyana",
"Hong Kong",
"Heard Island and McDonald Islands",
"Honduras",
"Croatia",
"Haiti",
"Hungary",
"Indonesia",
"Ireland",
"Israel",
"Isle of Man",
"India",
"British Indian Ocean Territory",
"Iraq",
"Iran",
"Iceland",
"Italy",
"Jersey",
"Jamaica",
"Jordan",
"Japan",
"Kenya",
"Kyrgyzstan",
"Cambodia",
"Kiribati",
"Comoros",
"Saint Kitts and Nevis",
"North Korea",
"South Korea",
"Kosovo",
"Kuwait",
"Cayman Islands",
"Kazakhstan",
"Laos",
"Lebanon",
"Saint Lucia",
"Liechtenstein",
"Sri Lanka",
"Liberia",
"Lesotho",
"Lithuania",
"Luxembourg",
"Latvia",
"Libya",
"Morocco",
"Monaco",
"Moldova",
"Montenegro",
"Saint Martin",
"Madagascar",
"Marshall Islands",
"Macedonia",
"Mali",
"Myanmar",
"Mongolia",
"Macao",
"Northern Mariana Islands",
"Martinique",
"Mauritania",
"Montserrat",
"Malta",
"Mauritius",
"Maldives",
"Malawi",
"Mexico",
"Malaysia",
"Mozambique",
"Namibia",
"New Caledonia",
"Niger",
"Norfolk Island",
"Nigeria",
"Nicaragua",
"Netherlands",
"Norway",
"Nepal",
"Nauru",
"Niue",
"New Zealand",
"Oman",
"Panama",
"Peru",
"French Polynesia",
"Papua New Guinea",
"Philippines",
"Pakistan",
"Poland",
"Saint Pierre and Miquelon",
"Pitcairn",
"Puerto Rico",
"Palestinian Territory",
"Portugal",
"Palau",
"Paraguay",
"Qatar",
"Reunion",
"Romania",
"Serbia",
"Russia",
"Rwanda",
"Saudi Arabia",
"Solomon Islands",
"Seychelles",
"Sudan",
"South Sudan",
"Sweden",
"Singapore",
"Saint Helena",
"Slovenia",
"Svalbard and Jan Mayen",
"Slovakia",
"Sierra Leone",
"San Marino",
"Senegal",
"Somalia",
"Suriname",
"Sao Tome and Principe",
"El Salvador",
"Sint Maarten",
"Syria",
"Swaziland",
"Turks and Caicos Islands",
"Chad",
"French Southern Territories",
"Togo",
"Thailand",
"Tajikistan",
"Tokelau",
"East Timor",
"Turkmenistan",
"Tunisia",
"Tonga",
"Turkey",
"Trinidad and Tobago",
"Tuvalu",
"Taiwan",
"Tanzania",
"Ukraine",
"Uganda",
"United States Minor Outlying Islands",
"United States",
"Uruguay",
"Uzbekistan",
"Vatican",
"Saint Vincent and the Grenadines",
"Venezuela",
"British Virgin Islands",
"U.S. Virgin Islands",
"Vietnam",
"Vanuatu",
"Wallis and Futuna",
"Samoa",
"Yemen",
"Mayotte",
"South Africa",
"Zambia",
"Zimbabwe",
"Serbia and Montenegro",
"Netherlands Antilles",
"Asia",
"South America",
"Africa",
"Europe",
"Oceania",
"Antarctica",
"North America"
);

$file="module-7.x-0.1.de.po";//已經包含了部分詞的翻譯文件
$count_false=0;
$count_true=0;
foreach ($array_country as $country) {//逐個詞進行查找
  $flag=FALSE;
  $fp=fopen($file,"r");
  while(!(feof($fp))) {//翻譯文件從頭查到尾
    $line=fgets($fp);
//    print "$line";
    if ($line=='msgid "'.$country.'"'."\n") {//找到則标記、退出
      $line=fgets($fp);
//      print "$line";
      $country_t=substr($line,8,-2);
      $flag=TRUE;
      break;
    }
  }
  fclose($fp);
  if ($flag) {
    $count_true++;
    print "$count_true: $country -> $country_t\n";//打印找到的
  } else {
    $count_false++;
    print "$count_false: $country !!!\n";//打印沒有找到的
  }
}
print "\n------\n";
print "translated count: $count_true\n";//統計找到的總數
print "need translate count: $count_false\n";//統計沒有找到的總數
?>

 

發表新回應

Plain text

  • 不允許使用 HTML 標籤。
  • 自動將網址與電子郵件地址轉變為連結。
  • 自動斷行和分段。