Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
keremgunduz86 committed Sep 7, 2020
1 parent 06f1432 commit a6b9cc0
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 396 deletions.
81 changes: 0 additions & 81 deletions README.md

This file was deleted.

26 changes: 0 additions & 26 deletions bin/check-strings.rb

This file was deleted.

23 changes: 0 additions & 23 deletions bin/fetch-strings.rb

This file was deleted.

Empty file modified bin/migrate-keys.rb
100644 → 100755
Empty file.
10 changes: 5 additions & 5 deletions resources/keys-to-update.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"onfido_accessibility_camera_capture_shutter": "kerem_onfido_accessibility_camera_capture_shutter",
"onfido_accessibility_camera_document_capture_view": "kerem_onfido_accessibility_camera_document_capture_view",
"onfido_accessibility_camera_face_capture_view": "kerem_onfido_accessibility_camera_face_capture_view",
"onfido_capture_face_step_1": "kerem_onfido_capture_face_step_1",
"onfido_capture_face_step_2": "kerem_onfido_capture_face_step_2"
"accessibility_camera_capture_shutter": "test_accessibility_camera_capture_shutter",
"accessibility_camera_document_capture_view": "test_accessibility_camera_document_capture_view",
"accessibility_camera_face_capture_view": "test_accessibility_camera_face_capture_view",
"capture_face_step_1": "test_capture_face_step_1",
"capture_face_step_2": "test_capture_face_step_2"
}
2 changes: 1 addition & 1 deletion src/common/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Onfido

LOCALIZE_RESULTS_REGEX_IOS = /"(.+)"\s*=\s*"(.+)"/
LOCALIZE_RESULTS_REGEX_ANDROID = /<string name="(.+)">"(.+)"<\/string>/
LOCALIZE_RESULTS_REGEX_ANDROID = /<string name=\s*\"(.+)\"\s*>(.+)<\/string>/

PLATFORMS = ['ios', 'android', 'web']
LANGUAGES = ['en_US', 'de_DE', 'es_ES', 'fr_FR']
Expand Down
8 changes: 8 additions & 0 deletions src/common/dir-helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ def self.save_file(contents, file_path)
end
end

def self.project_root
File.expand_path("../..", File.dirname(__FILE__))
end

def self.resources
"#{project_root}/resources"
end

def self.create_clean_directory_in_path(name, path)
directory_to_create = File.expand_path(name, path)
create_clean_directory(directory_to_create)
Expand Down
4 changes: 2 additions & 2 deletions src/file-parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class FileParser

##
# This class reads strings file and transforms each "key"="value" line to hash key/value and returns hash
# e.g "onfido_blur_detection_subtitle" = "Make sure your \"dummy string\" details are clear and unobstructed" should be extracted to
# string_map["onfido_blur_detection_subtitle"] = "Make sure your \"dummy string\" details are clear and unobstructed"
# e.g "blur_detection_subtitle" = "Make sure your \"dummy string\" details are clear and unobstructed" should be extracted to
# string_map["blur_detection_subtitle"] = "Make sure your \"dummy string\" details are clear and unobstructed"
##

def self.to_hash(file_path)
Expand Down
131 changes: 0 additions & 131 deletions src/localisation-file-updater.rb

This file was deleted.

27 changes: 16 additions & 11 deletions src/migrate-keys-runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'open3'

require_relative 'common/constants'
require_relative 'common/dir-helper'
require_relative 'common/logger'
require_relative 'common/execution-steps'

Expand All @@ -23,16 +24,16 @@ def run

begin
keys_to_update_dict = retrieve_keys_to_update
puts Terminal::Table.new title: 'Keys to be updated', rows: keys_to_update_dict
puts Terminal::Table.new(title: 'Keys to be updated', headings: ['Old key', 'New key'], rows: keys_to_update_dict)
execution_steps.success
file_list = retrieve_files_to_update
puts Terminal::Table.new title: 'Files to be updated', rows: file_array
file_dict = file_list.map { |f| ['File', f] }
puts Terminal::Table.new(title: 'File List', rows: file_dict)
execution_steps.success
file_list.each { |file|
update_file(file, keys_to_update_dict)
}
execution_steps.success
Logger.success('Steps completed.')
rescue Exception => exception
Logger.error(exception.message)
execution_steps.failed
Expand All @@ -45,7 +46,7 @@ def run
private

def retrieve_keys_to_update
keys_file_path = "#{__FILE__}/../resources/keys-to-update.json"
keys_file_path = "#{DirHelper.resources}/keys-to-update.json"
keys_file_content = File.read(keys_file_path)
keys_to_update_dict = JSON.parse(keys_file_content)
end
Expand All @@ -68,20 +69,24 @@ def string_file_extension

def update_file(file, key_dict)
content = File.read(file)
content_changed = false
key_dict.each do | old_key, new_key |
File.readlines(file).each do |line|
if pair_match = line.match(LOCALIZE_RESULTS_REGEX_IOS)
puts "pair_match: #{pair_match}"
if pair_match = line.match(regex_for_string_file)
translation_key = pair_match[1]
if translation_key == old_key
entry = build__and_return_string_entry(new_key, pair_match[2])
content_changed = true
entry = build_and_return_string_entry(new_key, pair_match[2])
content = content.sub(line, entry)
Logger.success("Updated #{translation_key} with #{new_key}.")
break
end
end
end
end
File.open(file, "w") {|file| file.puts content }
if content_changed
File.open(file, "w") {|file| file.puts content }
end
end

def regex_for_string_file
Expand All @@ -92,11 +97,11 @@ def regex_for_string_file
end
end

def build__and_return_string_entry(key, value)
def build_and_return_string_entry(key, value)
if platform == 'ios'
return "\"#{key}\" = \"#{value}\";"
return "\"#{key}\" = \"#{value}\";\n"
elsif platform == 'android'
return "<string name=\"#{key}\">#{value}</string>"
return "<string name=\"#{key}\">#{value}</string>\n"
end
end
end
Expand Down
Loading

0 comments on commit a6b9cc0

Please sign in to comment.