Class: Fastlane::Helper::PoesieHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::PoesieHelper
- Defined in:
- lib/fastlane/plugin/poesie/helper/poesie_helper.rb
Class Method Summary collapse
-
.list_of_languages(api_token, project_id) ⇒ Object
class methods that you define here become available in your action as ‘Helper::PoesieHelper.your_method`.
- .path_for_localized_file(languages, filename = nil, strings_path = nil) ⇒ Object
Class Method Details
.list_of_languages(api_token, project_id) ⇒ Object
class methods that you define here become available in your action as ‘Helper::PoesieHelper.your_method`
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fastlane/plugin/poesie/helper/poesie_helper.rb', line 11 def self.list_of_languages(api_token, project_id) uri = URI('https://api.poeditor.com/v2/languages/list') res = Net::HTTP.post_form(uri, 'api_token' => api_token, 'id' => project_id, 'type' => 'json') json = JSON.parse(res.body) unless json['response']['status'] == 'success' r = json['response'] puts "Error #{r['code']} (#{r['status']})\n#{r['message']}" exit 1 end json["result"]["languages"].map { |lan| lan["code"] } end |
.path_for_localized_file(languages, filename = nil, strings_path = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fastlane/plugin/poesie/helper/poesie_helper.rb', line 23 def self.path_for_localized_file(languages, filename = nil, strings_path = nil) require 'find' if filename.nil? filename = "Localizable.strings" end if strings_path.nil? strings_path = Dir.pwd end paths = {} Find.find(strings_path) do |path| if FileTest.file?(path) && File.basename(path) == filename languages.each { |lang| if File.basename(File.dirname(path)) == "#{lang}.lproj" paths[lang] = path end } Find.prune else next end end paths end |