Provide a translation object based on the parent and the translation_locale
 current value.
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
258683
def bind(self, field_name, parent):
        
        super(TranslatedFieldsField, self).bind(field_name, parent)

        # Expect 1-on-1 for now. Allow using source as alias,
        # but it should not be a dotted path for now
        related_name = self.source or field_name

        # This could all be done in __init__(), but by moving the code here,
        # it's possible to auto-detect the parent model.
        if self.shared_model is not None and self.serializer_class is not None:
            return

        # Fill in the blanks
        if self.serializer_class is None:
            if self.shared_model is None:
                # Auto detect parent model
                from .serializers import TranslatableModelSerializer
                if not isinstance(parent, TranslatableModelSerializer):
                    raise TypeError("Expected 'TranslatableModelSerializer' as serializer base class")
                if not issubclass(parent.Meta.model, TranslatableModel):
                    raise TypeError("Expected 'TranslatableModel' for the parent model")

                self.shared_model = parent.Meta.model

            # Create serializer based on shared model.
            translated_model = self.shared_model._parler_meta[related_name]
            self.serializer_class = create_translated_fields_serializer(
                self.shared_model, related_name=related_name,
                meta={'fields': translated_model.get_translated_fields()}
            )
        else:
            if not issubclass(self.serializer_class.Meta.model, TranslatedFieldsModel):
                raise TypeError("Expected 'TranslatedFieldsModel' for the serializer model")
796383
def _get_translated_model(self, language_code=None, use_fallback=False, auto_create=False, meta=None):
        
        if self._parler_meta is None:
            raise ImproperlyConfigured("No translation is assigned to the current model!")
        if self._translations_cache is None:
            raise RuntimeError("Accessing translated fields before super.__init__() is not possible.")

        if not language_code:
            language_code = self._current_language
            if language_code is None:
                raise ValueError(get_null_language_error())

        if meta is None:
            meta = self._parler_meta.root  # work on base model by default

        local_cache = self._translations_cache[meta.model]

        # 1. fetch the object from the local cache
        try:
            object = local_cache[language_code]

            # If cached object indicates the language doesn't exist, need to query the fallback.
            if not is_missing(object):
                return object
        except KeyError:
            # 2. No cache, need to query
            # Check that this object already exists, would be pointless otherwise to check for a translation.
            if not self._state.adding and self.pk is not None:
                prefetch = self._get_prefetched_translations(meta=meta)
                if prefetch is not None:
                    # 2.1, use prefetched data
                    # If the object is not found in the prefetched data (which contains all translations),
                    # it's pointless to check for memcached (2.2) or perform a single query (2.3)
                    for object in prefetch:
                        if object.language_code == language_code:
                            local_cache[language_code] = object
                            _cache_translation(object)  # Store in memcached
                            return object
                else:
                    # 2.2, fetch from memcached
                    object = get_cached_translation(self, language_code, related_name=meta.rel_name, use_fallback=use_fallback)
                    if object is not None:
                        # Track in local cache
                        if object.language_code != language_code:
                            local_cache[language_code] = MISSING  # Set fallback marker
                        local_cache[object.language_code] = object
                        return object
                    elif is_missing(local_cache.get(language_code, None)):
                        # If get_cached_translation() explicitly set the "does not exist" marker,
                        # there is no need to try a database query.
                        pass
                    else:
                        # 2.3, fetch from database
                        try:
                            object = self._get_translated_queryset(meta).get(language_code=language_code)
                        except meta.model.DoesNotExist:
                            pass
                        else:
                            local_cache[language_code] = object
                            _cache_translation(object)  # Store in memcached
                            return object

        # Not in cache, or default.
        # Not fetched from DB

        # 3. Auto create?
        if auto_create:
            # Auto create policy first (e.g. a __set__ call)
            kwargs = {
                'language_code': language_code,
            }
            if self.pk:
                # ID might be None at this point, and Django does not allow that.
                kwargs['master'] = self

            object = meta.model(**kwargs)
            local_cache[language_code] = object
            # Not stored in memcached here yet, first fill + save it.
            return object

        # 4. Fallback?
        fallback_msg = None
        lang_dict = get_language_settings(language_code)

        if language_code not in local_cache:
            # Explicitly set a marker for the fact that this translation uses the fallback instead.
            # Avoid making that query again.
            local_cache[language_code] = MISSING  # None value is the marker.
            if not self._state.adding or self.pk is not None:
                _cache_translation_needs_fallback(self, language_code, related_name=meta.rel_name)

        fallback_choices = [lang_dict['code']] + list(lang_dict['fallbacks'])
        if use_fallback and fallback_choices:
            # Jump to fallback language, return directly.
            # Don't cache under this language_code
            for fallback_lang in fallback_choices:
                if fallback_lang == language_code:  # Skip the current language, could also be fallback 1 of 2 choices
                    continue

                try:
                    return self._get_translated_model(fallback_lang, use_fallback=False, auto_create=auto_create, meta=meta)
                except meta.model.DoesNotExist:
                    pass

            fallback_msg = " (tried fallbacks {0})".format(', '.join(lang_dict['fallbacks']))

        # None of the above, bail out!
        raise meta.model.DoesNotExist(
            "{0} does not have a translation for the current language!\n"
            "{0} ID #{1}, language={2}{3}".format(self._meta.verbose_name, self.pk, language_code, fallback_msg or ''
        ))
273372
def add_localedir_translations(self, localedir):
        """"""
        global _localedirs
        if localedir in self.localedirs:
            return
        self.localedirs.append(localedir)
        full_localedir = os.path.join(localedir, 'locale')
        if os.path.exists(full_localedir):
            translation = self._new_gnu_trans(full_localedir)
            self.merge(translation)
756663
function(translateAttr, translationId, scope, interpolateParams, defaultTranslationText) {
          if (translationId) {
            $translate(translationId, interpolateParams, translateInterpolation, defaultTranslationText)
              .then(function (translation) {
                applyTranslation(translation, scope, true, translateAttr);
              }, function (translationId) {
                applyTranslation(translationId, scope, false, translateAttr);
              });
          } else {
            // as an empty string cannot be translated, we can solve this using successful=false
            applyTranslation(translationId, scope, false, translateAttr);
          }
        }
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)
1032387
def prepare_translations!
      stash.each do |locale, attrs|
        if attrs.any?
          translation = record.translations.find_by_locale(locale)
          translation ||= record.translations.build(:locale => locale)
          attrs.each{ |name, value| translation[name] = value }
        end
      end
      reset
    end
521591
function replaceLocale(locale, translations) {
    return store.dispatch({
      type: "".concat(moduleName, "/replaceLocale"),
      locale: locale,
      translations: translations
    });
  }
1168497
def get_translation_from_instance(instance, lang):
        
        try:
            translation = get_translation(instance, lang)
        except (AttributeError, ObjectDoesNotExist):
            translation = None
        return translation
218509
def translate(self, from_lang=None, to="de"):
        
        if from_lang is None:
            from_lang = self.translator.detect(self.string)
        return self.translator.translate(self.string,
                                         from_lang=from_lang, to_lang=to)
609042
def get_cached_translation(instance, language_code=None, related_name=None, use_fallback=False):
    
    if language_code is None:
        language_code = instance.get_current_language()

    translated_model = instance._parler_meta.get_model_by_related_name(related_name)
    values = _get_cached_values(instance, translated_model, language_code, use_fallback)
    if not values:
        return None

    try:
        translation = translated_model(**values)
    except TypeError:
        # Some model field was removed, cache entry is no longer working.
        return None

    translation._state.adding = False
    return translation
694199
def get_catalog(self, locale):
        """"""
        with translation.override(locale):
            translation_engine = DjangoTranslation(locale, domain=self.domain, localedirs=self.paths)

            trans_cat = translation_engine._catalog
            trans_fallback_cat = translation_engine._fallback._catalog if translation_engine._fallback else {}

            return trans_cat, trans_fallback_cat
981643
def get_translator (domain, directory, languages=None,
                    translatorklass=Translator, fallback=False,
                    fallbackklass=NullTranslator):
    """"""
    translator = gettext.translation(domain, localedir=directory,
            languages=languages, class_=translatorklass, fallback=fallback)
    if not isinstance(translator, gettext.GNUTranslations) and fallbackklass:
        translator = fallbackklass()
    return translator
1025578
def with_translations(self, **kwargs):
        

        force = kwargs.pop("force", False)

        if self._prefetch_translations_done and force is False:
            return self

        self._prefetched_translations_cache = utils.get_grouped_translations(
            self, **kwargs
        )
        self._prefetch_translations_done = True

        return self._clone()
682122
def translation_for(locale)
      @translation_caches ||= {}
      # Need to temporary switch of merging, because #translations uses
      # #attributes method too, to avoid stack level too deep error.
      @stop_merging_translated_attributes = true
      unless @translation_caches[locale]
        _translation = translations.find_by_locale(locale)
        _translation ||= translations.build(:locale => locale)
        @translation_caches[locale] = _translation
      end
      @stop_merging_translated_attributes = false
      @translation_caches[locale]
    end
898086
def get_translation_for(package_name: str) -> gettext.NullTranslations:
    """"""
    localedir = None
    for localedir in pkg_resources.resource_filename(package_name, 'i18n'), None:
        localefile = gettext.find(package_name, localedir)  # type: ignore
        if localefile:
            break
    else:
        pass
    return gettext.translation(package_name, localedir=localedir, fallback=True)
1032518
def setCurrentLocale(self, locale):
        
        locale = str(locale)
        for i in xrange(self.count()):
            if self.itemData(i) == locale:
                self.setCurrentIndex(i)
                return True
        return False