Module: GScraper::Languages

Defined in:
lib/gscraper/languages.rb

Overview

Since:

  • 0.3.0

Constant Summary collapse

NAMES =

The list of language names

Since:

  • 0.3.0

%w[
  af
  ar
  be
  bg
  ca
  cs
  da
  de
  el
  en
  eo
  es
  et
  fa
  fi
  fr
  hi
  hr
  hu
  hy
  id
  is
  it
  iw
  ja
  ko
  lt
  lv
  nl
  no
  pl
  pt
  ro
  ru
  sk
  sl
  sr
  sv
  sw
  th
  tl
  tr
  uk
  vi
  zh-CN
  zh-TW
]

Class Method Summary collapse

Class Method Details

.find(locale) ⇒ String

Looks up the language for the given locale.

Parameters:

  • locale (String)

    A locale.

Returns:

  • (String)

    The language used by the locale.

Since:

  • 0.3.0



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/gscraper/languages.rb', line 87

def Languages.find(locale)
  if locale =~ /^zh_CN/
    'zh-CN'
  elsif locale =~ /^zh_TW/
    'zh-TW'
  else
    if (match = locale.match(/^([^_@]+)([_@].+)?$/))
      match[1] if (match[1] && NAMES.include?(match[1]))
    end
  end
end

.nativeString

Determines the native language.

Returns:

  • (String)

    The native language.

Since:

  • 0.3.0



105
106
107
108
# File 'lib/gscraper/languages.rb', line 105

def Languages.native
  language = ENV['LANG'] || 'en'
  Languages.find(language)
end