本文整理汇总了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;
}
}
}