문제

I've a php language file, that lists values in an array.

I want to transform this into .po file.

php file looks like this:

<?php 

$LANG_ = array(

// advanced search buttons
"_search1"              => "Start Search",
"_search2"              => "Hide Search Box",
"_search3"              => "Search",

// page numbering
"_pn1"              => "Page %CURRENT_PAGE% of %TOTAL_PAGES%",
"_pn2"              => "<< First",
"_pn3"              => "Last >>",

// _tpl_article-add.php
"_tpl_article-add1"             => "Article Submission Form",
"_tpl_article-add2"             => "Submit Article",
"_tpl_article-add3"             => "Article Submitted Successfully",


// errors
"_err14"            => "Delete",
"_err144"           => "Display Image",
"_err15"            => "Edit",
"_err16"            => "View",

);
?>

This is just an example, file itself is huge, over 3000 lines. It would kill me to insert every single one of these into a po catalog manually. Is there something that can automate this for me?

I'm using poedit.

Thanks, I'm new to this, so any insight will be useful...

도움이 되었습니까?

해결책

The first entry is the file header, look into an existing gettext file (-po) what is needed. The escaping I did with addslashes; maybe you need to do more.

$fh = fopen("en.po", 'w');
fwrite($fh, "#\n");
fwrite($fh, "msgid \"\"\n");
fwrite($fh,  "msgstr \"\"\n");

foreach ($LANG_ as $key => $value) {
    $key = addslashes($key);
    $value = addslashes($value);
    fwrite($fh, "\n");
    fwrite($fh, "msgid \"$key\"\n");
    fwrite($fh, "msgstr \"$value\"\n");
}
fclose($fh);

다른 팁

Try php2po which will convert a PHP array into PO files and will also make sure that all of your escaping is correct. The PO file can then be edited in a tool like Poedit or Virtaal.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top