本文整理汇总了PHP中Translations::translate_entry方法的典型用法代码示例。如果您正苦于以下问题:PHP Translations::translate_entry方法的具体用法?PHP Translations::translate_entry怎么用?PHP Translations::translate_entry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translations
的用法示例。
在下文中一共展示了Translations::translate_entry方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
function import($translations)
{
$this->set_memory_limit('256M');
if (!isset($this->project) || !$this->project) {
$this->project = GP::$project->get($this->project_id);
}
$locale = GP_Locales::by_slug($this->locale);
$user = wp_get_current_user();
$current_translations_list = GP::$translation->for_translation($this->project, $this, 'no-limit', array('status' => 'current', 'translated' => 'yes'));
$current_translations = new Translations();
foreach ($current_translations_list as $entry) {
$current_translations->add_entry($entry);
}
unset($current_translations_list);
$translations_added = 0;
foreach ($translations->entries as $entry) {
if (empty($entry->translations)) {
continue;
}
$is_fuzzy = in_array('fuzzy', $entry->flags);
if ($is_fuzzy && !apply_filters('gp_translation_set_import_fuzzy_translations', true, $entry, $translations)) {
continue;
}
$create = false;
if ($translated = $current_translations->translate_entry($entry)) {
// we have the same string translated
// create a new one if they don't match
$entry->original_id = $translated->original_id;
$translated_is_different = array_pad($entry->translations, $locale->nplurals, null) != $translated->translations;
$create = apply_filters('gp_translation_set_import_over_existing', $translated_is_different);
} else {
// we don't have the string translated, let's see if the original is there
$original = GP::$original->by_project_id_and_entry($this->project->id, $entry, '+active');
if ($original) {
$entry->original_id = $original->id;
$create = true;
}
}
if ($create) {
if ($user) {
$entry->user_id = $user->ID;
}
$entry->translation_set_id = $this->id;
$entry->status = apply_filters('gp_translation_set_import_status', $is_fuzzy ? 'fuzzy' : 'current');
// check for errors
$translation = GP::$translation->create($entry);
$translation->set_status($entry->status);
$translations_added += 1;
}
}
gp_clean_translation_set_cache($this->id);
do_action('gp_translations_imported', $this->id);
return $translations_added;
}
示例2: import
function import($translations)
{
@ini_set('memory_limit', '256M');
if (!isset($this->project) || !$this->project) {
$this->project = GP::$project->get($this->project_id);
}
$locale = GP_Locales::by_slug($this->locale);
$current_translations_list = GP::$translation->for_translation($this->project, $this, 'no-limit', array('status' => 'current', 'translated' => 'yes'));
$current_translations = new Translations();
foreach ($current_translations_list as $entry) {
$current_translations->add_entry($entry);
}
unset($current_translations_list);
$translations_added = 0;
foreach ($translations->entries as $entry) {
if (empty($entry->translations)) {
continue;
}
if (in_array('fuzzy', $entry->flags)) {
continue;
}
$create = false;
if ($translated = $current_translations->translate_entry($entry)) {
// we have the same string translated
// create a new one if they don't match
$entry->original_id = $translated->original_id;
$create = array_pad($entry->translations, $locale->nplurals, null) != $translated->translations;
} else {
// we don't have the string translated, let's see if the original is there
$original = GP::$original->by_project_id_and_entry($this->project->id, $entry);
if ($original) {
$entry->original_id = $original->id;
$create = true;
}
}
if ($create) {
$entry->translation_set_id = $this->id;
$entry->status = 'current';
// check for errors
$translation = GP::$translation->create($entry);
$translation->set_as_current();
$translations_added += 1;
}
}
wp_cache_delete($this->id, 'translation_set_status_breakdown');
return $translations_added;
}
示例3: import
public function import($translations)
{
$this->set_memory_limit('256M');
if (!isset($this->project) || !$this->project) {
$this->project = GP::$project->get($this->project_id);
}
$locale = GP_Locales::by_slug($this->locale);
$user = wp_get_current_user();
$current_translations_list = GP::$translation->for_translation($this->project, $this, 'no-limit', array('status' => 'current', 'translated' => 'yes'));
$current_translations = new Translations();
foreach ($current_translations_list as $entry) {
$current_translations->add_entry($entry);
}
unset($current_translations_list);
$translations_added = 0;
foreach ($translations->entries as $entry) {
if (empty($entry->translations)) {
continue;
}
$is_fuzzy = in_array('fuzzy', $entry->flags);
/**
* Filter whether to import fuzzy translations.
*
* @since 1.0.0
*
* @param bool $import_over Import fuzzy translation. Default true.
* @param Translation_Entry $entry Translation entry object to import.
* @param Translations $translations Translations collection.
*/
if ($is_fuzzy && !apply_filters('gp_translation_set_import_fuzzy_translations', true, $entry, $translations)) {
continue;
}
$create = false;
if ($translated = $current_translations->translate_entry($entry)) {
// we have the same string translated
// create a new one if they don't match
$entry->original_id = $translated->original_id;
$translated_is_different = array_pad($entry->translations, $locale->nplurals, null) != $translated->translations;
/**
* Filter whether to import over an existing translation on a translation set.
*
* @since 1.0.0
*
* @param bool $import_over Import over an existing translation.
*/
$create = apply_filters('gp_translation_set_import_over_existing', $translated_is_different);
} else {
// we don't have the string translated, let's see if the original is there
$original = GP::$original->by_project_id_and_entry($this->project->id, $entry, '+active');
if ($original) {
$entry->original_id = $original->id;
$create = true;
}
}
if ($create) {
if ($user) {
$entry->user_id = $user->ID;
}
$entry->translation_set_id = $this->id;
/**
* Filter the the status of imported translations of a translation set.
*
* @since 1.0.0
*
* @param string $status The status of imported translations.
*/
$entry->status = apply_filters('gp_translation_set_import_status', $is_fuzzy ? 'fuzzy' : 'current');
// check for errors
$translation = GP::$translation->create($entry);
$translation->set_status($entry->status);
$translations_added += 1;
}
}
gp_clean_translation_set_cache($this->id);
/**
* Fires after translations have been imported to a translation set.
*
* @since 1.0.0
*
* @param int $translation_set The ID of the translation set the import was made into.
*/
do_action('gp_translations_imported', $this->id);
return $translations_added;
}