本文整理汇总了PHP中Gettext\Translations::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Translations::insert方法的具体用法?PHP Translations::insert怎么用?PHP Translations::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gettext\Translations
的用法示例。
在下文中一共展示了Translations::insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
/**
* main
*
*/
public function main()
{
$schemaPo = APP . 'Locale' . DS . 'schema.pot';
$conn = ConnectionManager::get('default');
$collection = $conn->schemaCollection();
$translations = new Translations();
$tables = $collection->listTables();
foreach ($tables as $table) {
$translations->insert($table, Inflector::humanize(Inflector::underscore($table)));
$translations->insert($table, Inflector::humanize(Inflector::underscore(Inflector::singularize($table))));
$columns = $collection->describe($table)->columns();
foreach ($columns as $column) {
$c = $collection->describe($table)->column($column);
$comment = $c['comment'];
$t = new Translation($table . '.' . $column, Inflector::humanize(Inflector::underscore($column)));
$translations[] = $t;
$t->setTranslation($comment);
$t = new Translation($table . '.' . $column, Inflector::humanize(Inflector::underscore(Inflector::singularize($table))) . ' ' . Inflector::humanize(Inflector::underscore($column)));
$translations[] = $t;
$t->setTranslation($comment);
}
}
$poString = $translations->toPoString();
$caked = preg_replace('/msgctxt "([^"]+)"/i', '#: \\1', $poString);
$this->createFile($schemaPo, $caked);
}
示例2: process
public static function process(\Twig_Node $node, Translations $translations, $file)
{
$fileReference = str_replace(realpath(self::$rootDir . '/../') . '/', "", $file);
if ($node instanceof TransNode) {
//Process nodes that {% trans %} blocks
$body = new \Twig_Node_Expression_Constant($node->getNode('body')->getAttribute('data'), $node->getLine());
$compiledTranslation = eval('return ' . self::$twig->compile($body) . ';');
$translations->insert('', $compiledTranslation)->addReference($fileReference, $node->getLine());
}
if ($node instanceof \Twig_Node_Expression_Function) {
//Process nodes that are function expressions
if ($node->getAttribute('name') == '__') {
//Check the function name for __()
foreach ($node->getNode('arguments') as $argument) {
//Grab the argument
$key = eval('return ' . self::$twig->compile($argument) . ';');
$translations->insert('', $key)->addReference($fileReference, $node->getLine());
break;
//I only needed the first argument in my implementation
}
}
}
//Recursively loop through the AST
foreach ($node as $child) {
if ($child instanceof \Twig_Node) {
self::process($child, $translations, $file);
}
}
}
示例3: saveGettextFunctions
/**
* Search for specific functions and create translations.
*
* @param array $functions The gettext functions to search
* @param Translations $translations The translations instance where save the values
* @param string $file The filename used to the reference
*/
public function saveGettextFunctions(array $functions, Translations $translations, $file = '')
{
foreach ($this->getFunctions() as $function) {
list($name, $line, $args) = $function;
if (!isset($functions[$name])) {
continue;
}
$translation = null;
switch ($functions[$name]) {
case '__':
if (!isset($args[0])) {
continue 2;
}
$original = $args[0];
if ($original !== '') {
$translation = $translations->insert('', $original);
}
break;
case 'n__':
if (!isset($args[1])) {
continue 2;
}
$original = $args[0];
$plural = $args[1];
if ($original !== '') {
$translation = $translations->insert('', $original, $plural);
}
break;
case 'p__':
if (!isset($args[1])) {
continue 2;
}
$context = $args[0];
$original = $args[1];
if ($original !== '') {
$translation = $translations->insert($context, $original);
}
break;
default:
throw new Exception('Not valid functions');
}
if (isset($translation)) {
$translation->addReference($file, $line);
if (isset($function[3])) {
foreach ($function[3] as $extractedComment) {
$translation->addExtractedComment($extractedComment);
}
}
}
}
}
示例4: extractTranslatableSiteStrings
/**
* return \GetText\Translations $translations;
*/
public function extractTranslatableSiteStrings()
{
$translations = new Translations();
$translations->insert('SiteName', Config::get('concrete.site'));
$phpParser = new \C5TL\Parser\Php();
$blockTemplatesParser = new \C5TL\Parser\BlockTemplates();
$themesPresetsParser = new \C5TL\Parser\ThemePresets();
$processApplication = array(DIRNAME_BLOCKS => array($phpParser, $blockTemplatesParser), DIRNAME_ELEMENTS => array($phpParser), DIRNAME_CONTROLLERS => array($phpParser), DIRNAME_MAIL_TEMPLATES => array($phpParser), DIRNAME_PAGE_TYPES => array($phpParser), DIRNAME_PAGES => array($phpParser), DIRNAME_THEMES => array($phpParser, $themesPresetsParser, $blockTemplatesParser), DIRNAME_VIEWS => array($phpParser));
foreach ($processApplication as $dirname => $parsers) {
if (is_dir(DIR_APPLICATION . '/' . $dirname)) {
foreach ($parsers as $parser) {
/* @var $parser \C5TL\Parser */
$fullDirname = DIR_APPLICATION . '/' . $dirname;
if (is_dir($fullDirname)) {
$parser->parseDirectory($fullDirname, DIRNAME_APPLICATION . '/' . $dirname, $translations);
}
}
}
}
if (is_dir(DIR_PACKAGES)) {
$packages = Package::getInstalledList();
foreach ($packages as $package) {
$fullDirname = DIR_PACKAGES . '/' . $package->getPackageHandle();
$phpParser->parseDirectory($fullDirname, DIRNAME_PACKAGES . '/' . $dirname, $translations);
}
}
// Now, we grab dynamic content that's part of our site that we translate dynamically
$dynamicTranslations = $this->getDynamicTranslations();
$translations->mergeWith($dynamicTranslations);
return $translations;
}
示例5: exportTranslations
/**
* @deprecated
*/
public function exportTranslations()
{
$translations = new Translations();
foreach ($this->getList() as $type) {
$translations->insert('AttributeTypeName', $type->getAttributeTypeName());
}
return $translations;
}
示例6: exportTranslations
/**
* @deprecated
*/
public function exportTranslations()
{
$translations = new Translations();
$sets = $this->entityManager->getRepository('\\Concrete\\Core\\Entity\\Attribute\\Set')->findAll();
foreach ($sets as $set) {
$translations->insert('AttributeSet', $set->getAttributeSetName());
}
return $translations;
}
示例7: exportTranslations
/**
* @deprecated
*/
public function exportTranslations()
{
$translations = new Translations();
$keys = $this->entityManager->getRepository('\\Concrete\\Core\\Entity\\Attribute\\Key\\Key')->findAll();
foreach ($keys as $key) {
$translations->insert('AttributeKeyName', $key->getAttributeKeyName());
}
return $translations;
}
示例8: exportTranslations
/**
* @deprecated
*/
public function exportTranslations()
{
$translations = new Translations();
$list = $this->getList();
$akcNameMap = array('collection' => 'Page attributes', 'user' => 'User attributes', 'file' => 'File attributes');
foreach ($list as $category) {
$akcHandle = $category->getAttributeKeyCategoryHandle();
$translations->insert('AttributeKeyCategory', isset($akcNameMap[$akcHandle]) ? $akcNameMap[$akcHandle] : ucwords(str_replace(array('_', '-', '/'), ' ', $akcHandle)));
}
return $translations;
}
示例9: parseDirectoryDo
/**
* {@inheritdoc}
*
* @see \C5TL\Parser::parseDirectoryDo()
*/
protected function parseDirectoryDo(\Gettext\Translations $translations, $rootDirectory, $relativePath, $subParsersFilter, $exclude3rdParty)
{
$themesPresets = array();
$prefix = $relativePath === '' ? '' : "{$relativePath}/";
$matches = null;
foreach (array_merge(array(''), $this->getDirectoryStructure($rootDirectory, $exclude3rdParty)) as $child) {
$presetsAbsDirectory = $child === '' ? $rootDirectory : "{$rootDirectory}/{$child}";
if (preg_match('%(?:^|/)themes/\\w+/css/presets$%', $presetsAbsDirectory, $matches)) {
$dirList = @scandir($presetsAbsDirectory);
if ($dirList === false) {
throw new \Exception("Unable to parse directory {$presetsAbsDirectory}");
}
$shownChild = $child === '' ? rtrim($prefix, '/') : $prefix . $child;
foreach ($dirList as $file) {
if ($file[0] !== '.' && preg_match('/[^.].*\\.less$/i', $file)) {
$fileAbs = "{$presetsAbsDirectory}/{$file}";
if (is_file($fileAbs)) {
$content = @file_get_contents($fileAbs);
if ($content === false) {
throw new \Exception("Error reading file '{$fileAbs}'");
}
$content = str_replace("\r", "\n", str_replace("\r\n", "\n", $content));
// Strip multiline comments
$content = preg_replace_callback('|/\\*.*?\\*/|s', function ($matches) {
return str_repeat("\n", substr_count($matches[0], "\n"));
}, $content);
foreach (array("'", '"') as $quote) {
if (preg_match('%(?:^|\\n|;)[ \\t]*@preset-name:\\s*' . $quote . '([^' . $quote . ']*)' . $quote . '\\s*(?:;|$)%s', $content, $matches)) {
$presetName = $matches[1];
$presetLine = null;
$p = strpos($content, $matches[0]);
if ($p !== false) {
$presetLine = substr_count(substr($content, 0, $p), "\n") + 1;
}
if (!isset($themesPresets[$presetName])) {
$themesPresets[$presetName] = array();
}
$themesPresets[$presetName][] = array($shownChild . "/{$file}", $presetLine);
break;
}
}
}
}
}
}
}
foreach ($themesPresets as $themesPreset => $references) {
$translation = $translations->insert('PresetName', ucwords(str_replace(array('_', '-', '/'), ' ', $themesPreset)));
foreach ($references as $reference) {
$translation->addReference($reference[0], $reference[1]);
}
}
}
示例10: fromString
/**
* {@inheritDoc}
*/
public static function fromString($string, Translations $translations = null, $file = '')
{
if ($translations === null) {
$translations = new Translations();
}
if ($entries = json_decode($string, true)) {
foreach ($entries as $original => $translation) {
$translations->insert(null, $original)->setTranslation($translation);
}
}
return $translations;
}
示例11: insertTranslation
/**
* Extract and insert a new translation.
*
* @param Translations $translations
* @param string $key
* @param string $message
*/
protected static function insertTranslation(Translations $translations, $key, $message)
{
$context_glue = '\\u0004';
$key = explode($context_glue, $key);
$context = isset($key[1]) ? array_shift($key) : '';
$original = array_shift($key);
$translation = array_shift($message);
$plural_translation = array_shift($message);
$entry = $translations->insert($context, $original);
$entry->setTranslation($translation);
$entry->setPluralTranslation($plural_translation);
}
示例12: exportTranslations
public static function exportTranslations()
{
$translations = new Translations();
$em = \Database::connection()->getEntityManager();
$options = $em->getRepository(SelectValueOption::class)->findAll();
/**
* @var $option SelectValueOption
*/
foreach ($options as $option) {
$translations->insert('SelectAttributeValue', $option->getSelectAttributeOptionValue());
}
return $translations;
}
示例13: parseFileTypes
/**
* Parse the file type names.
*
* @param \Gettext\Translations $translations
* @param string $rootDirectory
* @param string $prefix
* @param string[] $directoryAlternatives
*/
private function parseFileTypes(\Gettext\Translations $translations, $rootDirectory, $prefix, $directoryAlternatives)
{
foreach ($directoryAlternatives as $subDir) {
$rel = $subDir === '' ? 'app.php' : "{$subDir}/app.php";
$fileAbs = $rootDirectory . '/' . $rel;
if (!is_file($fileAbs)) {
continue;
}
$fileRel = $prefix . $rel;
$configFile = new \C5TL\Util\ConfigFile($fileAbs);
$config = $configFile->getArray();
if (isset($config['file_types']) && is_array($config['file_types'])) {
$fileTypes = $config['file_types'];
foreach (array_keys($fileTypes) as $fileType) {
$translation = $translations->insert('', $fileType);
$translation->addReference($fileRel);
}
}
}
}
示例14: handleArray
/**
* Handle an array of translations and append to the Translations instance
*
* @param array $content
* @param Translations $translations
*/
public static function handleArray(array $content, Translations $translations)
{
$content = $content['messages'];
$translations_info = isset($content['']) ? $content[''] : null;
unset($content['']);
if (isset($translations_info['domain'])) {
$translations->setDomain($translations_info['domain']);
}
$context_glue = '\\u0004';
foreach ($content as $key => $message) {
$key = explode($context_glue, $key);
$context = isset($key[1]) ? array_shift($key) : '';
$original = array_shift($key);
$plural = array_shift($message);
$translation = array_shift($message);
$plural_translation = array_shift($message);
$entry = $translations->insert($context, $original, $plural);
$entry->setTranslation($translation);
$entry->setPluralTranslation($plural_translation);
}
}
示例15: extract
/**
* Handle an array of translations and append to the Translations instance.
*
* @param array $content
* @param Translations $translations
*/
public static function extract(array $content, Translations $translations)
{
$messages = current($content);
$headers = isset($messages['']) ? $messages[''] : null;
unset($messages['']);
if (!empty($headers['domain'])) {
$translations->setDomain($headers['domain']);
}
if (!empty($headers['lang'])) {
$translations->setLanguage($headers['lang']);
}
if (!empty($headers['plural-forms'])) {
$translations->setHeader(Translations::HEADER_PLURAL, $headers['plural-forms']);
}
$context_glue = '\\u0004';
foreach ($messages as $key => $translation) {
$key = explode($context_glue, $key);
$context = isset($key[1]) ? array_shift($key) : '';
$translations->insert($context, array_shift($key))->setTranslation(array_shift($translation))->setPluralTranslations($translation);
}
}