Home  >  Article  >  php教程  >  检查Drupal的.po翻译文件中缺少哪些词的PHP程序

检查Drupal的.po翻译文件中缺少哪些词的PHP程序

WBOY
WBOYOriginal
2016-06-06 20:10:561412browse

最近在处理一些小问题的时候积累了一些小程序来解决,现在记录下来以备后用。 Drupal多语言网站是通过.po的翻译文件来导入翻译数据的,有一批国家/地区名称需要导入,而以前的.po文件中包括了一部分,只需要找出并添加新的词,这个过程人工来核对比较麻烦,

  最近在处理一些小问题的时候积累了一些小程序来解决,现在记录下来以备后用。

  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";//统计没有找到的总数
?>

?

自由标签:

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn