localize_string_filter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dd5bf64555ba5905b81c9c1e1891d65f4b68d7bb
4
+ data.tar.gz: 1b6b7088f0ae9e324d09e89c1df72860f2904dc1
5
+ SHA512:
6
+ metadata.gz: 59b2ffd7d70c097ddfb6625430c861fc5d7ace1372105d72a9f9b4d7083b4cc3e13e87e8cc98826a1c4d089da91182971a6745da90117e7d82a6bcdd4b4f1b37
7
+ data.tar.gz: 05404844aec923f5ebabe93a647d47464d0e42620ccf96cc82745661d3cd9b0cd6cf043fb11e4214048dfa155f276779eda7a5bf9070e2f289502800bfd3e2b2
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at yhlssdone@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in localize_string_filter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 HongliYu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # LocalizeStringFilter
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/localize_string_filter`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ Remove keys which never referenced by project in Localizable.strings
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'localize_string_filter'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install localize_string_filter
22
+
23
+ ## Usage
24
+
25
+ Remove keys which never referenced by project in Localizable.strings
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/localize_string_filter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "localize_string_filter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "localize_string_filter"
4
+
5
+ puts LocalizeStringFilter.run()
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module LocalizeStringFilter
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,130 @@
1
+ require "localize_string_filter/version"
2
+ require 'fileutils'
3
+
4
+ def traverse_swift_files(file_path, swift_files)
5
+ if File.directory? file_path
6
+ Dir.foreach(file_path) do |file|
7
+ if file !="." and file !=".."
8
+ traverse_swift_files(file_path+"/"+file, swift_files)
9
+ end
10
+ end
11
+ else
12
+ if file_path.end_with? ".swift"
13
+ swift_files << file_path
14
+ # puts "File:#{File.basename(file_path)}, Size:#{File.size(file_path)}"
15
+ end
16
+ end
17
+ end
18
+
19
+ def collect_keys(strings_path)
20
+ strings_keys = Array.new
21
+ File.open(strings_path, "r") do |file|
22
+ file.each_line do |line|
23
+ if line.start_with? "\""
24
+ temp_array = line.split('=')
25
+ quotation_indexes = Array.new
26
+ temp_array[0].split("").each_with_index do |character, index|
27
+ if character == '"'
28
+ quotation_indexes << index
29
+ end
30
+ end
31
+ str = temp_array[0][quotation_indexes[0], quotation_indexes[1] + 1]
32
+ strings_keys << str
33
+ end
34
+ end
35
+ end
36
+ return strings_keys
37
+ end
38
+
39
+ def collect_missing_keys(localized_keys, swift_files)
40
+ missing_keys = Array.new
41
+ percentCount = 0
42
+
43
+ localized_keys.each do |key|
44
+ the_key_is_valid = false
45
+
46
+ # output progress
47
+ percentCount = percentCount + 1
48
+ precent = ((percentCount.to_f / localized_keys.count.to_f) * 10000).round / 10000.0
49
+ str = (precent * 100).to_s
50
+ # print "searching key: #{key} \n"
51
+ puts "#{str[0,4]}% || searching key: #{key}"
52
+
53
+ swift_files.each do |swift_file|
54
+ if File.readlines(swift_file).any?{ |l| l[key] }
55
+ the_key_is_valid = true
56
+ break
57
+ end
58
+ end
59
+ if !the_key_is_valid
60
+ missing_keys << key
61
+ end
62
+ end
63
+ return missing_keys
64
+ end
65
+
66
+ def output_missing_keys(missing_keys, project_path)
67
+ missing_keys_output_path = project_path + "/missing_keys.txt"
68
+ File.open(missing_keys_output_path, "w+") do |f|
69
+ missing_keys.each {
70
+ |element| f.puts(element)
71
+ }
72
+ end
73
+ puts "\n missing_keys: #{missing_keys}"
74
+ puts "check the file: #{missing_keys_output_path}"
75
+ end
76
+
77
+ def delete_missing_keys(missing_keys, strings_path)
78
+ missing_keys.each do |key|
79
+ open(strings_path, 'r') do |f|
80
+ open(strings_path + '.tmp', 'w') do |f2|
81
+ f.each_line do |line|
82
+ f2.write(line) unless line.start_with? key
83
+ end
84
+ end
85
+ end
86
+ FileUtils.mv strings_path + '.tmp', strings_path
87
+ end
88
+ end
89
+
90
+ module LocalizeStringFilter
91
+ def self.run()
92
+
93
+ puts "input project path: "
94
+ project_path = gets.chomp
95
+ if project_path.empty?
96
+ puts "error: invalid project_path"
97
+ return
98
+ end
99
+
100
+ puts "input .strings file path: "
101
+ strings_path = gets.chomp
102
+ if strings_path.empty?
103
+ puts "error: invalid strings_path"
104
+ return
105
+ end
106
+
107
+ puts "running..."
108
+ if File.directory?(project_path)
109
+ swift_files = Array.new
110
+ traverse_swift_files(project_path, swift_files)
111
+ localized_keys = collect_keys(strings_path)
112
+ missing_keys = collect_missing_keys(localized_keys, swift_files)
113
+ output_missing_keys(missing_keys, project_path)
114
+
115
+ puts "remove all missing keys directly from .strings file? Y/(N)"
116
+ need_delete_missing_keys = gets.chomp
117
+ if need_delete_missing_keys.empty? || need_delete_missing_keys == "Y"
118
+ puts "deleting..."
119
+ delete_missing_keys(missing_keys, strings_path)
120
+ else
121
+ puts "check missing_keys.txt file in project path, and remove keys manually"
122
+ end
123
+ puts "done."
124
+
125
+ else
126
+ puts "error: project_path is not a directory"
127
+ end
128
+ end
129
+
130
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'localize_string_filter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "localize_string_filter"
8
+ spec.version = LocalizeStringFilter::VERSION
9
+ spec.authors = ["HongliYu"]
10
+ spec.email = ["yhlssdone@gmail.com"]
11
+
12
+ spec.summary = %q{Remove keys which never referenced by project in Localizable.strings.}
13
+ spec.description = %q{Remove keys which never referenced by project in Localizable.strings.}
14
+ spec.homepage = "https://github.com/HongliYu/localize_string_filter."
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = "localize_string_filter"
19
+ spec.require_paths = ["lib"]
20
+ spec.required_ruby_version = '>= 2.0.0'
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: localize_string_filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - HongliYu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Remove keys which never referenced by project in Localizable.strings.
42
+ email:
43
+ - yhlssdone@gmail.com
44
+ executables:
45
+ - localize_string_filter
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/localize_string_filter
57
+ - bin/setup
58
+ - lib/localize_string_filter.rb
59
+ - lib/localize_string_filter/version.rb
60
+ - localize_string_filter.gemspec
61
+ homepage: https://github.com/HongliYu/localize_string_filter.
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 2.0.0
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.6.6
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Remove keys which never referenced by project in Localizable.strings.
85
+ test_files: []