Sha256: d10f3cdb6a8269bd00aa1564aec55c52f3362e63f76a3c9a88e7f5c5cb68785d

Contents?: true

Size: 1.06 KB

Versions: 27

Compression:

Stored size: 1.06 KB

Contents

module CBin
  class Trans
    class Helper

      def self.instance
        @instance ||= new
      end

      def yaml_file
        File.join(Pod::Config.instance.home_dir, 'zh2hant.yml')
      end

      def load_trans_map
        require 'yaml'
        down_load_yaml unless File.exist?(yaml_file)
        contents = YAML.safe_load(File.open(yaml_file))
        contents.to_hash
      end

      def down_load_yaml
        require 'open-uri'
        URI.open('http://aomi-ios-repo.oss-cn-shenzhen.aliyuncs.com/zh2hant.yml') do |i|
          File.open(yaml_file, 'w+') do |f|
            f.write(i.read)
          end
        end
      end

      def trans_zh_cn_str(input)
        @trans_map_invert ||= load_trans_map.invert
        out = []
        input.each_char do |c|
          out << (@trans_map_invert[c] || c)
        end
        out.join('')
      end

      def trans_zh_hk_str(input)
        @trans_map ||= load_trans_map
        out = []
        input.each_char do |c|
          out << (@trans_map[c] || c)
        end
        out.join('')
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
cocoapods-aomi-bin-0.1.28 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.27 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.26 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.25 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.24 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.23 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.22 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.21 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.20 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.19 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.18 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.17 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.16 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.15 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.14 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.13 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.12 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.11 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.10 lib/cocoapods-lhj-bin/helpers/trans_helper.rb
cocoapods-aomi-bin-0.1.9 lib/cocoapods-lhj-bin/helpers/trans_helper.rb