Detects locale in given attributes and executes given block for it.
 Param: Hash of attributes
 Param: Proc
504176
def with_given_locale(attributes, &block)
      attributes.symbolize_keys! if attributes.respond_to?(:symbolize_keys!)
      if locale = attributes.try(:delete, :locale)
        Mongoid::Globalize.with_locale(locale, &block)
      else
        yield
      end
    end
928603
def enforce_available_locales!(locale)
      if locale != false && config.enforce_available_locales
        raise I18n::InvalidLocale.new(locale) if !locale_available?(locale)
      end
    end
1371866
def locale=(value)
      if value
        config = I18n.config.respond_to?(:original_config) ? I18n.config.original_config : I18n.config
        config.locale = value
      end

      super(default_locale)
    end
834409
def norm_locale (loc):
    """"""
    loc = locale.normalize(loc)
    # split up the locale into its base components
    pos = loc.find('@')
    if pos >= 0:
        loc = loc[:pos]
    pos = loc.find('.')
    if pos >= 0:
        loc = loc[:pos]
    pos = loc.find('_')
    if pos >= 0:
        loc = loc[:pos]
    return loc
1290250
def translation_activate_block(function=None, language=None):
    

    def _translation_activate_block(function):
        def _decorator(*args, **kwargs):
            tmp_language = translation.get_language()
            try:
                translation.activate(language or settings.LANGUAGE_CODE)
                return function(*args, **kwargs)
            finally:
                translation.activate(tmp_language)
        return wraps(function)(_decorator)

    if function:
        return _translation_activate_block(function)
    else:
        return _translation_activate_block
147074
private void initLocaleSelect() {

        if (m_availableLocales.size() < 2) {
            return;
        }
        Map<String, String> selectOptions = new HashMap<String, String>();
        for (Entry<String, String> localeEntry : m_availableLocales.entrySet()) {
            if (m_contentLocales.contains(localeEntry.getKey())) {
                selectOptions.put(localeEntry.getKey(), localeEntry.getValue());
            } else {
                selectOptions.put(localeEntry.getKey(), localeEntry.getValue() + " [-]");
            }
        }
        if (m_localeSelect == null) {
            m_localeSelect = new CmsSelectBox(selectOptions);
            m_toolbar.insertRight(m_localeSelect, 1);
            m_localeSelect.addStyleName(I_CmsLayoutBundle.INSTANCE.generalCss().inlineBlock());
            m_localeSelect.getElement().getStyle().setWidth(100, Unit.PX);
            m_localeSelect.getElement().getStyle().setVerticalAlign(VerticalAlign.MIDDLE);
            m_localeSelect.addValueChangeHandler(new ValueChangeHandler<String>() {

                public void onValueChange(ValueChangeEvent<String> event) {

                    switchLocale(event.getValue());
                }
            });
        } else {
            m_localeSelect.setItems(selectOptions);
        }
        m_localeSelect.setFormValueAsString(m_locale);
        if (m_deleteLocaleButton == null) {
            m_deleteLocaleButton = createButton(
                Messages.get().key(Messages.GUI_TOOLBAR_DELETE_LOCALE_0),
                "opencms-icon-remove-locale");
            m_deleteLocaleButton.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {

                    confirmDeleteLocale();
                }
            });
            m_toolbar.insertRight(m_deleteLocaleButton, 2);
        }
        if (m_contentLocales.size() > 1) {
            m_deleteLocaleButton.enable();
        } else {
            m_deleteLocaleButton.disable(Messages.get().key(Messages.GUI_TOOLBAR_CANT_DELETE_LAST_LOCALE_0));
        }
        if (m_copyLocaleButton == null) {
            m_copyLocaleButton = createButton(
                I_CmsButton.ButtonData.COPY_LOCALE_BUTTON.getTitle(),
                I_CmsButton.ButtonData.COPY_LOCALE_BUTTON.getIconClass());
            m_copyLocaleButton.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {

                    openCopyLocaleDialog();
                }
            });
            m_toolbar.insertRight(m_copyLocaleButton, 3);
        }
    }
937538
private Template parseTemplate(Resource resource, String name, Locale locale, String encoding, Object args) throws IOException, ParseException {
        if (resource == null) {
            resource = loadResource(name, locale, encoding);
        }
        long start = logger != null && logger.isDebugEnabled() ? System.currentTimeMillis() : 0;
        String source = resource.getSource();
        try {
            if (templateFilter != null) {
                source = templateFilter.filter(resource.getName(), source);
            }
            Node root = templateParser.parse(source, 0);
            Map<String, Class<?>> parameterTypes = useRenderVariableType && args != null ? new DelegateMap<String, Class<?>>(new TypeMap(convertMap(args))) : null;
            Template template = translator.translate(resource, root, parameterTypes);
            if (logger != null && logger.isDebugEnabled()) {
                logger.debug("Parsed the template " + name + ", eslapsed: " + (System.currentTimeMillis() - start) + "ms.");
            }
            return template;
        } catch (ParseException e) {
            throw AbstractTemplate.toLocatedParseException(e, resource);
        }
    }
383029
def fetch_attribute(locale, name)
      translation = record.translation_for(locale)
      return translation && translation.send(name)
    end
789739
private Context translateStatementBlock(WyilFile.Stmt.Block block, Context context) {
		for (int i = 0; i != block.size(); ++i) {
			WyilFile.Stmt stmt = block.get(i);
			context = translateStatement(stmt, context);
			if (stmt instanceof WyilFile.Stmt.Return) {
				return null;
			}
		}
		return context;
	}
305728
def _add_locale(locale, strings)
      `t = document.createElement('template');
      document.body.appendChild(t);
      t.classList.add('i18n');
      t.setAttribute('data-lang', #{locale})`

      strings.each do |k, v|
        `e=document.createElement('p');
        t.content.appendChild(e);
        e.id=#{k.gsub('.', '-')};
        e.textContent=#{v}`
      end
    end
576044
def lookup(locale, key, scope = [], options = {})
      return super unless ActiveRecord::Base.connected? && CopycatTranslation.table_exists?
      cct = CopycatTranslation.where(locale: locale.to_s, key: key.to_s).first
      return cct.value if cct
      value = super(locale, key, scope, options)
      if value.is_a?(String) || value.nil?
        CopycatTranslation.create(locale: locale.to_s, key: key.to_s, value: value)
      end
      value
    end
1147852
function getLocale (key) {
    var locale;

    if (key && key._locale && key._locale._abbr) {
        key = key._locale._abbr;
    }

    if (!key) {
        return globalLocale;
    }

    if (!isArray$2(key)) {
        //short-circuit everything else
        locale = loadLocale(key);
        if (locale) {
            return locale;
        }
        key = [key];
    }

    return chooseLocale(key);
}
72665
def detect_html(str)
      str = detect_unicode_bom(str)

      # Attempt Charlock detection
      if str.encoding == Encoding::BINARY
        charlock_detect(str)
      end

      # Fallback to environment's external encoding
      if str.encoding == Encoding::BINARY
        str.force_encoding(Encoding.default_external)
      end

      str
    end
964759
def _setup_locale(self, locale: str = locales.DEFAULT_LOCALE) -> None:
        
        if not locale:
            locale = locales.DEFAULT_LOCALE

        locale = locale.lower()
        if locale not in locales.SUPPORTED_LOCALES:
            raise UnsupportedLocale(locale)

        self.locale = locale
745243
def _detect_encoding(stdout):
        
        if hasattr(stdout, 'encoding') and stdout.encoding:
            return stdout.encoding

        if os.environ.get('LANG'):
            encoding = os.environ.get('LANG').split('.')[-1]

            # validate the encoding string
            ret = None
            try:
                ret = codecs.lookup(encoding)
            except LookupError:
                pass
            if ret:
                return encoding

        return locale.getpreferredencoding()
1233870
def attributes_with_locale=(new_attributes, guard_protected_attributes = true)
      return if new_attributes.nil?
      attributes = new_attributes.dup
      attributes.stringify_keys!

      attributes = sanitize_for_mass_assignment(attributes) if guard_protected_attributes
      send(:locale=, attributes["locale"]) if attributes.has_key?("locale") and respond_to?(:locale=)

      send(:attributes_without_locale=, attributes, guard_protected_attributes)
    end
1118950
def prefix_locale?(locale = Language.current.code)
      multi_language? && locale != ::I18n.default_locale.to_s
    end