本文整理匯總了PHP中Cake\I18n\I18n::loadPo方法的典型用法代碼示例。如果您正苦於以下問題:PHP I18n::loadPo方法的具體用法?PHP I18n::loadPo怎麽用?PHP I18n::loadPo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Cake\I18n\I18n
的用法示例。
在下文中一共展示了I18n::loadPo方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: putTranslations
/**
* TransifexLib::putTranslations()
*
* @param string $resource
* @param string $language
* @param string $file
* @throws \RuntimeException
* @return mixed
* @author Gustav Wellner Bou <wellner@solutica.de>
*/
public function putTranslations($resource, $language, $file)
{
$url = static::BASE_URL . 'project/{project}/resource/' . $resource . '/translation/' . $language;
if (function_exists('curl_file_create') && function_exists('mime_content_type')) {
$body = ['file' => curl_file_create($file, $this->_getMimeType($file), pathinfo($file, PATHINFO_BASENAME))];
} else {
$body = ['file' => '@' . $file];
}
try {
return $this->_post($url, $body, 'PUT');
} catch (RuntimeException $e) {
/* Handling a very specific exception due to a Transifex bug */
// Exception is thrown maybe just because the file only has empty translations
if (strpos($e->getMessage(), "We're not able to extract any string from the file uploaded for language") !== false) {
$catalog = I18n::loadPo($file);
unset($catalog['']);
if (count($catalog)) {
if (count(array_filter($catalog)) === 0) {
// PO file contains empty translations
// In that case Transifex throws an error although its not.
// Then we could just append one non empty translation to that file and send it again
// But apart from successfully sending this file again, it wont affect the remote translations
return ['strings_added' => 0, 'strings_updated' => 0, 'strings_delete' => 0];
}
throw new RuntimeException(sprintf('Could not extract any string from %s. Whereas file contains non-empty translation(s) for following key(s): %s.', $file, '"' . implode('", "', array_keys(array_filter($catalog))) . '"'));
} else {
throw new RuntimeException(sprintf('Could not extract any string from %s. File seems empty.', $file));
}
} else {
throw $e;
}
}
}