-
-
Save makshark/52b31c00ce198f22b998 to your computer and use it in GitHub Desktop.
descr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Language | |
AVAILABLE_LANGUAGE = ['en', 'ru'] | |
LANGUAGE = { | |
DEFAULT: 'en', | |
RU: 'ru', | |
EN: 'en' | |
} | |
def t(key) | |
translation = Translation.where(key: key).first | |
translation["text_#{get_language}"] if translation | |
end | |
def set_language(language) | |
language = LANGUAGE[:DEFAULT] unless AVAILABLE_LANGUAGE.include?(language) | |
session[:language] = language | |
end | |
def self.get_language | |
unless session[:language].present? | |
language = get_country == 'UA' ? LANGUAGE[:RU] : LANGUAGE[:DEFAULT] | |
set_language language | |
end | |
session[:language] | |
end | |
def get_country | |
require 'geoip' | |
remote_ip = request.remote_ip | |
geo_ip_path = Rails.root.join('db', 'GeoIP.dat') | |
@geoip ||= GeoIP.new(geo_ip_path) | |
@geoip.country(remote_ip).country_code2 if remote_ip != '127.0.0.1' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment