Sha256: e8f4db42ba0d2865252240415a938e852a044b5fd1c9ac9b43c1a5355f3a1e4c

Contents?: true

Size: 1.3 KB

Versions: 6

Compression:

Stored size: 1.3 KB

Contents

module Translator
  module Utils
    def locale_without_region(locale)
      case locale
      when 'zh-CN', 'cn'
        :cn
      when 'ja', 'ja-JP'
        :ja
      else
        :en
      end
    end

    def storage_folder(filename, locale)
      if filename.starts_with? '_documentation'
        dir_path = Pathname.new(file_uri(filename)).dirname.to_s
        "#{Rails.configuration.docs_base_path}/_documentation/#{locale}/#{dir_path}"
      elsif filename.starts_with? 'config/locales'
        Pathname.new(file_uri(filename)).dirname.to_s
      else
        dir_path = Pathname.new(file_uri(filename)).dirname.to_s
        "#{Rails.configuration.docs_base_path}/_documentation/#{locale}/#{dir_path}"
      end
    end

    def file_path(filename, locale)
      folder = storage_folder(filename, locale)
      file_name = if filename.starts_with? '_documentation'
                    Pathname.new(file_uri(filename)).basename.to_s
                  elsif filename.starts_with? 'config/locales'
                    "#{locale}#{Pathname.new(file_uri(filename)).extname}"
                  else
                    Pathname.new(file_uri(filename)).basename.to_s
                  end
      "#{folder}/#{file_name}"
    end

    def file_uri(filename)
      filename.gsub(%r{_documentation/[a-z]{2}/}, '')
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
station-0.0.101 lib/nexmo_developer/app/services/translator/utils.rb
station-0.0.100 lib/nexmo_developer/app/services/translator/utils.rb
station-0.0.97 lib/nexmo_developer/app/services/translator/utils.rb
station-0.0.96 lib/nexmo_developer/app/services/translator/utils.rb
station-0.0.95 lib/nexmo_developer/app/services/translator/utils.rb
station-0.0.93 lib/nexmo_developer/app/services/translator/utils.rb