module TwitterCldr

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

This code was adapted from GNU Classpath, but modified significantly. Ordinarily, derivatives are treated as falling under the same license as the original source, but classpath comes with the following exception:

“As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.”

We are assuming here that building a gem with the compiled version of bidi.java falls under these terms, specifically that we are “link(ing) this library with independent modules to produce an executable.” We are NOT including the original source code to avoid licensing restrictions, but it can be viewed here: developer.classpath.org/doc/java/text/Bidi-source.html

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Documentation: github.com/hunspell/hyphen/blob/21127cc8493a68d4fe9adbb71377b469b4f2b550/doc/tb87nemeth.pdf

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

unicode.org/reports/tr35/tr35-general.html#Transforms unicode.org/cldr/utility/transform.jsp

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

unicode.org/reports/tr35/tr35-general.html#Transforms unicode.org/cldr/utility/transform.jsp

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

unicode.org/reports/tr35/tr35-general.html#Transforms unicode.org/cldr/utility/transform.jsp

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright © 2006 Akira FUNAI <funai.akira@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Copyright 2012 Twitter, Inc www.apache.org/licenses/LICENSE-2.0

Constants

CLDR_LOCALE_MAP

maps cldr locales to twitter locales

DEFAULT_CALENDAR_TYPE
DEFAULT_LOCALE
LIB_DIR
RESOURCES_DIR
SPEC_DIR
SUPPORTED_LOCALES
SUPPORTED_LOCALES_FILE
TWITTER_LOCALE_MAP

TODO: convert this and all other hashes to 1.9 syntax maps twitter locales to cldr locales

VENDOR_DIR
VERSION

Attributes

disable_custom_locale_resources[RW]
locale[W]

Public Class Methods

convert_locale(locale) click to toggle source
# File lib/twitter_cldr.rb, line 114
def convert_locale(locale)
  locale = normalize_locale(locale)

  unless supported_locale?(locale)
    loc = TwitterCldr::Shared::Locale.parse(locale)
    max_supported = loc.max_supported

    if loc.dasherized == 'und' || !max_supported
      return locale
    end

    locale = normalize_locale(max_supported.dasherized)
  end

  locale
end
locale() click to toggle source
# File lib/twitter_cldr.rb, line 73
def locale
  # doing all this work in locale getter rather than locale setter makes it possible to use locale fallbacks
  # even if they were configured (or became available) after @locale was already assigned an unsupported locale
  locale = supported_locale?(@locale) ? @locale : find_fallback
  locale = DEFAULT_LOCALE if locale.to_s.empty?
  (supported_locale?(locale) ? locale : DEFAULT_LOCALE).to_sym
end
locale_fallbacks() click to toggle source
# File lib/twitter_cldr.rb, line 110
def locale_fallbacks
  @locale_fallbacks ||= []
end
normalize_locale(locale) click to toggle source
# File lib/twitter_cldr.rb, line 131
def normalize_locale(locale)
  return locale unless (locale.is_a?(String) || locale.is_a?(Symbol))

  locale = locale.to_sym
  locale = lowercase_locales_map.fetch(locale, locale)
  TWITTER_LOCALE_MAP.fetch(locale.downcase, locale)
end
register_locale_fallback(proc_or_locale) click to toggle source
# File lib/twitter_cldr.rb, line 94
def register_locale_fallback(proc_or_locale)
  case proc_or_locale
    when Symbol, String, Proc
      locale_fallbacks << proc_or_locale
    else
      raise "A locale fallback must be of type String, Symbol, or Proc."
  end
  nil
end
reset_locale_fallbacks() click to toggle source
# File lib/twitter_cldr.rb, line 104
def reset_locale_fallbacks
  locale_fallbacks.clear
  TwitterCldr.register_locale_fallback(lambda { I18n.locale if defined?(I18n) && I18n.respond_to?(:locale) })
  TwitterCldr.register_locale_fallback(lambda { FastGettext.locale if defined?(FastGettext) && FastGettext.respond_to?(:locale) })
end
resources() click to toggle source
# File lib/twitter_cldr.rb, line 69
def resources
  @resources ||= TwitterCldr::Resources::Loader.new
end
supported_locale?(locale) click to toggle source
# File lib/twitter_cldr.rb, line 148
def supported_locale?(locale)
  !!locale && supported_locales.include?(normalize_locale(locale))
end
supported_locales() click to toggle source
# File lib/twitter_cldr.rb, line 144
def supported_locales
  TwitterCldr::SUPPORTED_LOCALES
end
twitter_locale(locale) click to toggle source
# File lib/twitter_cldr.rb, line 139
def twitter_locale(locale)
  locale = locale.to_sym
  CLDR_LOCALE_MAP.fetch(locale, locale)
end
with_locale(locale) { || ... } click to toggle source
# File lib/twitter_cldr.rb, line 81
def with_locale(locale)
  raise "Unsupported locale" unless supported_locale?(locale)

  begin
    old_locale = @locale
    @locale = locale
    result = yield
  ensure
    @locale = old_locale
    result
  end
end

Protected Class Methods

find_fallback() click to toggle source
# File lib/twitter_cldr.rb, line 154
def find_fallback
  locale_fallbacks.reverse_each do |fallback|
    result = if fallback.is_a?(Proc)
      begin
        fallback.call
      rescue
        nil
      end
    else
      fallback
    end
    return result if result
  end
  nil
end
lowercase_locales_map() click to toggle source
# File lib/twitter_cldr.rb, line 170
def lowercase_locales_map
  @lowercase_locales_map ||= supported_locales.inject({}) do |memo, locale|
    lowercase = locale.to_s.downcase.to_sym
    memo[lowercase] = locale unless lowercase == locale
    memo
  end
end