Module: TranslationsHelper
- Defined in:
- app/helpers/translations_helper.rb
Overview
The TranslationsHelper module.
Class Method Summary (collapse)
-
+ (Object) cut_country(lang_code)
Remove the country from the language code, because bing translate doesn't support this.
-
+ (Object) is_valid_language(lang_code)
Check if the given language code is valid.
-
+ (Object) supported_language_codes
Get all currently supported language codes.
-
+ (Object) supported_language_codes_with_names
Get all currently supported language code including their names.
Class Method Details
+ (Object) cut_country(lang_code)
Remove the country from the language code, because bing translate doesn't support this. example: en_US -> en example: en-US -> en
26 27 28 29 30 31 32 |
# File 'app/helpers/translations_helper.rb', line 26 def self.cut_country(lang_code) if lang_code == nil return nil end language = lang_code.split("-")[0].split("_")[0] end |
+ (Object) is_valid_language(lang_code)
Check if the given language code is valid.
9 10 11 12 13 14 15 16 17 18 |
# File 'app/helpers/translations_helper.rb', line 9 def self.is_valid_language(lang_code) languages = supported_language_codes cut_lang_code = cut_country(lang_code) if languages.include?(cut_lang_code) return true else return false end end |
+ (Object) supported_language_codes
Get all currently supported language codes.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/helpers/translations_helper.rb', line 36 def self.supported_language_codes #require 'bing_translator' #translator = BingTranslator.new(BING_CLIENT_ID_DEV, BING_CLIENT_SECRET_DEV) #languages = translator.supported_language_codes #Rails.logger.info('DBG: supported languages: ' + languages.to_s) # http://msdn.microsoft.com/en-us/library/hh456380.aspx # update this string from time to time, don't query every time. languages = %w(ar bg ca zh-CHS zh-CHT cs da nl en et fi fr de el ht he hi mww hu id it ja tlh tlh-Qaak ko lv lt ms mt no fa pl pt ro ru sk sl es sv th tr uk ur vi cy) end |
+ (Object) supported_language_codes_with_names
Get all currently supported language code including their names.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/helpers/translations_helper.rb', line 51 def self.supported_language_codes_with_names [%w(Arabic ar), %w(Bulgarian bg), %w(Catalan ca), %w(Chinese Simplified zh-CHS), %w(Chinese Traditional zh-CHT), %w(Czech cs), %w(Danish da), %w(Dutch nl), %w(English en), %w(Estonian et), %w(Finnish fi), %w(French fr), %w(German de), %w(Greek el), %w(Haitian Creole ht), %w(Hebrew he), %w(Hindi hi), %w(Hmong Daw mww), %w(Hungarian hu), %w(Indonesian id), %w(Italian it), %w(Japanese ja), %w(Klingon tlh), %w(Klingon (pIqaD) tlh-Qaak), %w(Korean ko), %w(Latvian lv), %w(Lithuanian lt), %w(Malay ms), %w(Maltese mt), %w(Norwegian no), %w(Persian fa), %w(Polish pl), %w(Portuguese pt), %w(Romanian ro), %w(Russian ru), %w(Slovak sk), %w(Slovenian sl), %w(Spanish es), %w(Swedish sv), %w(Thai th), %w(Turkish tr), %w(Ukrainian uk), %w(Urdu ur), %w(Vietnamese vi), %w(Welsh cy)] end |