Skip to content

Commit

Permalink
Merge pull request #22 from iknow/zero-plural-options
Browse files Browse the repository at this point in the history
Allow passing of properties to the phraseapp API that are allowed
  • Loading branch information
gordoncl authored Sep 24, 2024
2 parents edb725a + 8c093a2 commit e2dbf0c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
17 changes: 16 additions & 1 deletion bin/phraseapp_updater
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,38 @@ class PhraseAppUpdaterCLI < Thor
class_option :file_format, type: :string, default: 'json', desc: 'Filetype of localization files.'
class_option :verbose, type: :boolean, default: false, desc: 'Verbose output'

# Options that mirror the PhraseApp API (https://developers.phrase.com/api/#post-/projects)
PHRASEAPP_CREATE_PROJECT_OPTIONS = {
zero_plural_form_enabled: {
type: :boolean,
desc: 'Displays the input fields for the \'ZERO\' plural form for every key as well although only some languages require the \'ZERO\' explicitly.'
},
}

desc 'setup <locale_path>',
'Create a new PhraseApp project, initializing it with locale files at <locale_path>. the new project ID is printed to STDOUT'
method_option :phraseapp_api_key, type: :string, required: true, desc: 'PhraseApp API key.'
method_option :phraseapp_project_name, type: :string, required: true, desc: 'Name for new PhraseApp project.'
method_option :parent_commit, type: :string, required: true, desc: 'git commit hash of initial locales'
method_option :remove_orphans, type: :boolean, default: true, desc: 'Remove keys not in the uploaded default locale'

PHRASEAPP_CREATE_PROJECT_OPTIONS.each do |name, params|
method_option(name, **params)
end

def setup(locales_path)
validate_readable_path!('locales', locales_path)

handle_errors do
phraseapp_opts = options.slice(*PHRASEAPP_CREATE_PROJECT_OPTIONS.keys)

updater, project_id = PhraseAppUpdater.for_new_project(
options[:phraseapp_api_key],
options[:phraseapp_project_name],
options[:file_format],
options[:parent_commit],
verbose: options[:verbose])
verbose: options[:verbose],
**phraseapp_opts)

updater.upload_directory(locales_path, remove_orphans: options[:remove_orphans])

Expand Down
4 changes: 2 additions & 2 deletions lib/phraseapp_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
class PhraseAppUpdater
using IndexBy

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

Expand Down
11 changes: 8 additions & 3 deletions lib/phraseapp_updater/phraseapp_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ def initialize(api_key, project_id, locale_file_class)
@locale_file_class = locale_file_class
end

def create_project(name, parent_commit)
# @param [Hash] opts Options to be passed to the {https://developers.phrase.com/api/#post-/projects PhraseApp API}
def create_project(name, parent_commit, **opts)
params = Phrase::ProjectCreateParameters.new(
name: name,
main_format: @locale_file_class.phraseapp_type)
# Merges name and main_format into opts to prevent overriding these properties
opts.merge(
name: name,
main_format: @locale_file_class.phraseapp_type
)
)

project = phraseapp_request(Phrase::ProjectsApi, :project_create, params)

Expand Down

0 comments on commit e2dbf0c

Please sign in to comment.