当前位置: 首页>>代码示例>>PHP>>正文


PHP I18n::loadPo方法代码示例

本文整理汇总了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;
         }
     }
 }
开发者ID:dereuromark,项目名称:cakephp-transifex,代码行数:43,代码来源:TransifexLib.php


注:本文中的Cake\I18n\I18n::loadPo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。