create default translation
435711
def create_default_translation
      translation = self.translations.build(value: self.name.to_s.split('.').last.titleize,
                                            lang: :en, status: 'accepted')
      translation.translator = TranslationCenter.prepare_translator

      translation.save
    end
425522
def translation
      if translation_enabled? 
        if !@translation || (@translation.locale != translation_locale)
          raise MissingParent, "Cannot create translations without a stored parent" if new_record?
          # try to find translation or build a new one
          @translation = translations.where(:locale => translation_locale).first || translations.build(:locale => translation_locale)
        end
        @translation
      else
        nil
      end
    end
1343959
def translate_with_annotation(key, options={})
      # default to an empty scope
      scope = []

      # In the case of a missing translation, fall back to letting TranslationHelper
      # put in span tag for a translation_missing.
      begin
        AnnoTranslate.translate_with_annotation(scope, @virtual_path, key, options.merge({:raise => true}))
      rescue AnnoTranslate::AnnoTranslateError, I18n::MissingTranslationData => exc
        # Call the original translate method
        str = translate_without_annotation(key, options)

        # View helper adds the translation missing span like:
        # In strict mode, do not allow TranslationHelper to add "translation missing" span like:
        # <span class="translation_missing">en, missing_string</span>
        if str =~ /span class\=\"translation_missing\"/
          # In strict mode, do not allow TranslationHelper to add "translation missing"
          raise if AnnoTranslate.strict_mode?

          # Invoke callback if it is defined
          AnnoTranslate.missing_translation_callback(exc, key, options)
        end

        str
      end
    end
580037
function createBasicTranslation(memberName, type, i, options) {
  var node = {};

  node["id"] = memberName;
  node["type"] = type;

  if (i["inheritdoc"] !== undefined) {
    node["inheritdoc"] = i["inheritdoc"].src;
  }
  else if (i["doc"] !== undefined) {
    node["description"] = i["doc"];
    // short description lasts until the first empty line
    node["short_description"] = node["description"].replace(/\n\n[\s\S]*$/, '\n');
  }
  else {
    node["undocumented"] = true;
  }

  node["line"] = i["linenr"];

  if (i["private"] !== undefined)
    node["private"] = i["private"];

  if (i["experimental"] !== undefined)
    node["experimental"] = i["experimental"];

  if (i["ignore"] !== undefined)
    node["ignore"] = i["ignore"];
    
  if (i["chainable"] !== undefined)
    node["chainable"] = i["chainable"];

  if (i["see"] !== undefined)
    node["related_to"] = i["see"].name;

  if (i["author"] !== undefined && i["author"].length > 0)
    node["author"] = i["author"].doc;
  
  if (i["version"] !== undefined)
    node["version"] = i["version"].doc;
  
  if (i["since"] !== undefined)
    node["since"] = i["since"].doc;

  if (i["author"] !== undefined)
    node["author"] = i["author"];

  if (i["related"] !== undefined)
    node["related"] = i["related"].name;

  if (options.customTags) {
    _.each(options.customTags, function(tag) {
      if (i[tag] !== undefined)
        node[tag] = i[tag];
    });
  }

  return node;
}
29423
public function translate()
	{
		$arguments = func_get_args();

		// Default translation parameters.
		$translate = array(
			'context' => $this->context(),
			'lang' => $this->lang(),
			'parameters' => $this->parameters(),
			'string' => $this->string(),
		);

		// Populate `$translate` variable with function arguments and/or model state.
		foreach ($this->_translate as $i => $element)
		{
			$this->_setup_element($translate, $element, $i, $arguments);
		}
		// Now that the basic data have been set, parameters that need to have context values.
		foreach ($this->_context_params as $parameter)
		{
			$translate['parameters'][$parameter] = $translate[self::CONTEXT];
		}

		// Translate using the populated data.
		return $this->i18n()
			->translate($translate['string'], $translate['context'], $translate['parameters'], $translate['lang']);
	}
360011
private function ensureHrefDefaultsToNull()
    {
        if (!($this->database->tableExists('tl_metamodel_translatedurl'))) {
            return;
        }

        foreach ($this->database->listFields('tl_metamodel_translatedurl', true) as $field) {
            if ('href' == $field['name'] && $field['type'] != 'index') {
                // Already updated?
                if ('NOT NULL' === $field['null']) {
                    $this->database->execute(
                        'ALTER TABLE `tl_metamodel_translatedurl` CHANGE `href` `href` varchar(255) NULL;'
                    );
                    return;
                }
                // Found!
                break;
            }
        }
    }
376337
function () {
          for (var key in translationIds) {
            if (translationIds.hasOwnProperty(key) && translationIds[key] !== undefined) {
              updateTranslation(key, translationIds[key], scope, scope.interpolateParams, scope.defaultText, scope.translateNamespace);
            }
          }
        }
531320
def create_translation_value
      batch_key = params[:batch_key]
      # batch_key might be "extra" or ..
      i18n_key = params[:i18n_key].sub(/^[.]*/, "")
      # regex above just incase there is a leading .
      full_i18n_key = batch_key.underscore.camelcase(:lower) + "." + i18n_key
      # eg propertyTypes.flat
      # subdomain = request.subdomain.downcase

      # http://stackoverflow.com/questions/5917355/find-or-create-race-conditions
      begin
        field_key = FieldKey.find_or_initialize_by(global_key: full_i18n_key)
        field_key.tag = batch_key
        field_key.save!
      rescue ActiveRecord::StatementInvalid => error
        @save_retry_count = (@save_retry_count || 5)
        retry if (@save_retry_count -= 1) > 0
        raise error
      end
      phrase = I18n::Backend::ActiveRecord::Translation.find_or_create_by(
        key: full_i18n_key,
      locale: params[:locale]
)
      phrase.value = params[:i18n_value]
      if phrase.save!
        I18n.backend.reload!
        return render json: { success: true }
      else
        return render json: { error: "unable to create phrase" }
      end
    end
551271
protected function _initTranslate()
    {
        $this->bootstrap('locale');

        $language = $this->locale->getLanguage();

        /*
         * Scan for files with -<languagecode> and disable notices when the requested
         * language is not found
         */
        $options = array( 'adapter'         => 'gettext',
                          'content'         => GEMS_LIBRARY_DIR . '/languages/',
                          'disableNotices'  => true,
                          'scan'            => \Zend_Translate::LOCALE_FILENAME);

        $translate = new \Zend_Translate($options);

        // If we don't find the needed language, use a fake translator to disable notices
        if (! $translate->isAvailable($language)) {
            $translate = \MUtil_Translate_Adapter_Potemkin::create();
        }

        //Now if we have a project specific language file, add it
        $projectLanguageDir = APPLICATION_PATH . '/languages/';
        if (file_exists($projectLanguageDir)) {
            $options['content']        = $projectLanguageDir;
            $options['disableNotices'] = true;
            $projectTranslations       = new \Zend_Translate($options);
            //But only when it has the requested language
            if ($projectTranslations->isAvailable($language)) {
                $translate->addTranslation(array('content' => $projectTranslations));
            }
            unset($projectTranslations);  //Save some memory
        }

        $translate->setLocale($language);
        \Zend_Registry::set('Zend_Translate', $translate);

        // Fix for _init resource being case insensitive
        $container = $this->getContainer();
        $adapter   = $translate->getAdapter();
        $container->translateAdapter = $adapter;
        $this->translateAdapter      = $adapter;

        return $translate;
    }
1106574
private function configureTranslations()
    {
        if (null !== array_key_exists('translation', $this->options) && is_array($this->options['translation'])) {
            $translatable = $this->options['entity'];
            $translation = $this->options['translation']['entity'];

            $id = sprintf('%s.%s_translation', $this->prefix, $this->resourceName);

            // Load metadata event mapping
            $mapping = [
                $translatable => $translation,
                $translation  => $translatable,
            ];
            if ($this->container->hasParameter('ekyna_admin.translation_mapping')) {
                $mapping = array_merge($this->container->getParameter('ekyna_admin.translation_mapping'), $mapping);
            }
            $this->container->setParameter('ekyna_admin.translation_mapping', $mapping);

            // Translation class parameter
            if (!$this->container->hasParameter($id.'.class')) {
                $this->container->setParameter($id.'.class', $translation);
            }

            // Inheritance mapping
            $this->configureInheritanceMapping($id, $translation, $this->options['translation']['repository']);
        }
    }
97297
def set_language(self, request, org):
        """"""
        if org:
            lang = org.language or settings.DEFAULT_LANGUAGE
            translation.activate(lang)
605335
function Translations (params, translations) {

  /** @type {Object} Store current translations source */
  this._translations = {};
  /** @type {Object} Store current stats for latest merge request */
  this._stats = {};
  /** @type {Object} Set default parameters */
  this.params = _.defaults(params, {
    "tree": false,
    "safeMode": false,
    "nullEmpty": false
  });
  // Set translations if given as parameter
  this.setTranslations(translations);
  // Initialize statistics
  this.initStats();

}
541362
def addTranslation(self,translation):
        '''
        '''
        if isinstance(translation, Translation):
            self.translations.append(translation)
        else:
            raise(TranslationError,
                   'translation Type should be Translation, not %s' % type(
                    translation)
                   )
396842
def _new_gnu_trans(self, localedir, use_null_fallback=True):
        
        use_null_fallback = False
        return gettext_module.translation(
            domain=self.domain,
            localedir=localedir,
            languages=[self.language],
            codeset='utf-8',
            fallback=use_null_fallback)
616620
function () {
            var target = arguments[0],
                regStr = '', langNum = arguments.length, i;
    
            target = String(target);
    
            for (i = 1; i < langNum; ++i) {
                switch( arguments[i] ) {
                    case 'en':
                        regStr += 'A-Za-z';
                        break;
                    case 'ko':
                        regStr += 'ㄱ-ㅣ가-힣';
                        break;
                    case 'number':
                        regStr += '0-9';
                        break;
                    default:
                        regStr += arguments[i].replace( /[(){}[\]*+?.\\^$|,\-]/g, '\\$&' );
                        break;
                }
            }
            return new RegExp( '[' + regStr + ']' ).test( target );
        }
426256
def create_for_locale
      field_key = FieldKey.find_by_global_key(params[:i18n_key])
      phrase = I18n::Backend::ActiveRecord::Translation.find_or_create_by(
        key: field_key.global_key,
      locale: params[:locale]
)
      unless phrase.value.present?
        I18n.backend.reload!
        phrase.value = params[:i18n_value]
        phrase.save!
      end
      render json: { success: true }
    end
1022077
function translateOptions(cliOptions) {
  return {
    config: cliOptions.config,
    output: cliOptions.output,
    watch : cliOptions.watch
  };
}