Class: PhraseAppUpdater

Inherits:
Object
  • Object
show all
Defined in:
lib/phraseapp_updater.rb,
lib/phraseapp_updater/differ.rb,
lib/phraseapp_updater/version.rb,
lib/phraseapp_updater/index_by.rb,
lib/phraseapp_updater/locale_file.rb,
lib/phraseapp_updater/phraseapp_api.rb,
lib/phraseapp_updater/yml_config_loader.rb,
lib/phraseapp_updater/locale_file/json_file.rb,
lib/phraseapp_updater/locale_file/yaml_file.rb

Defined Under Namespace

Modules: IndexBy Classes: Differ, LocaleFile, PhraseAppAPI, YMLConfigLoader

Constant Summary collapse

VERSION =
'3.2.0'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(phraseapp_api_key, phraseapp_project_id, file_format, default_locale: 'en', verbose: false) ⇒ PhraseAppUpdater

Returns a new instance of PhraseAppUpdater.



24
25
26
27
28
29
# File 'lib/phraseapp_updater.rb', line 24

def initialize(phraseapp_api_key, phraseapp_project_id, file_format, default_locale: 'en', verbose: false)
  @locale_file_class = LocaleFile.class_for_file_format(file_format)
  @default_locale    = default_locale
  @phraseapp_api     = PhraseAppAPI.new(phraseapp_api_key, phraseapp_project_id, @locale_file_class)
  @verbose           = verbose
end

Class Method Details

.for_new_project(phraseapp_api_key, phraseapp_project_name, file_format, parent_commit, verbose: false) ⇒ Object



13
14
15
16
17
# File 'lib/phraseapp_updater.rb', line 13

def self.for_new_project(phraseapp_api_key, phraseapp_project_name, file_format, parent_commit, verbose: false)
  api = PhraseAppAPI.new(phraseapp_api_key, nil, LocaleFile.class_for_file_format(file_format))
  project_id = api.create_project(phraseapp_project_name, parent_commit)
  return self.new(phraseapp_api_key, project_id, file_format, verbose: verbose), project_id
end

.lookup_project(phraseapp_api_key, phraseapp_project_name) ⇒ Object



19
20
21
22
# File 'lib/phraseapp_updater.rb', line 19

def self.lookup_project(phraseapp_api_key, phraseapp_project_name)
  api = PhraseAppAPI.new(phraseapp_api_key, nil, nil)
  api.lookup_project_id(phraseapp_project_name)
end

Instance Method Details

#diff_directories(our_path, their_path) ⇒ Object



31
32
33
34
# File 'lib/phraseapp_updater.rb', line 31

def diff_directories(our_path, their_path)
  (our_locales, their_locales) = load_locale_directories(our_path, their_path)
  diff_locale_files(our_locales, their_locales)
end

#download_to_directory(path) ⇒ Object



60
61
62
63
# File 'lib/phraseapp_updater.rb', line 60

def download_to_directory(path)
  locale_files = download_locale_files
  write_locale_directory(path, locale_files)
end

#merge_directories(our_path, their_path, ancestor_path, result_path) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/phraseapp_updater.rb', line 36

def merge_directories(our_path, their_path, ancestor_path, result_path)
  (our_locales, their_locales, ancestor_locales) =
    load_locale_directories(our_path, their_path, ancestor_path)

  merged_locales = merge_locale_files(our_locales, their_locales, ancestor_locales)

  write_locale_directory(result_path, merged_locales)
end

#merge_files(ours, theirs, ancestor, result) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/phraseapp_updater.rb', line 45

def merge_files(ours, theirs, ancestor, result)
  our_file, their_file = load_locale_files(ours, theirs)
  # Read the ancestor if provided
  ancestor_file = load_locale_file(ancestor) unless ancestor.nil?

  result_file = merge_locale_files(our_file, their_file, ancestor_file)

  write_locale_file(result, result_file)
end

#normalize_directory(source, destination) ⇒ Object



65
66
67
68
# File 'lib/phraseapp_updater.rb', line 65

def normalize_directory(source, destination)
  locales = load_locale_directory(source)
  write_locale_directory(destination, locales)
end

#read_parent_commitObject



74
75
76
# File 'lib/phraseapp_updater.rb', line 74

def read_parent_commit
  @phraseapp_api.read_parent_commit
end

#update_parent_commit(parent_commit) ⇒ Object



70
71
72
# File 'lib/phraseapp_updater.rb', line 70

def update_parent_commit(parent_commit)
  @phraseapp_api.update_parent_commit(parent_commit)
end

#upload_directory(path, remove_orphans: true) ⇒ Object



55
56
57
58
# File 'lib/phraseapp_updater.rb', line 55

def upload_directory(path, remove_orphans: true)
  locales = load_locale_directory(path)
  upload_locale_files(locales, remove_orphans: remove_orphans)
end