Browse Source

Start on ruby class to fetch and add translations

Antony Male 10 years ago
parent
commit
61ed36c063
2 changed files with 28 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 27 0
      build/TxClient.rb

+ 1 - 0
.gitignore

@@ -28,6 +28,7 @@ obj/
 
 #Project files
 [Bb]uild/
+!/build
 
 #NuGet
 packages/

+ 27 - 0
build/TxClient.rb

@@ -0,0 +1,27 @@
+require 'open-uri'
+require 'json'
+require 'openssl'
+
+class TxClient
+  TX_BASE = 'https://www.transifex.com/api/2/project/synctrayzor'
+  STATS_URL = TX_BASE + '/resource/strings/stats'
+  TRANSLATION_URL = TX_BASE + '/resource/strings/translation/%s'
+
+  def initialize(user, password)
+    @user, @password = user, password
+  end
+
+  def request(uri)
+    open(uri, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE, http_basic_authentication: [@user, @password]) do |f|
+      JSON.parse(f.read)
+    end
+  end
+
+  def list_translations(completion_percent = 75)
+    request(STATS_URL).select do |lang, stats|
+      stats['translated_entities'].fdiv(stats['translated_entities'] + stats['untranslated_entities']) * 100 > completion_percent
+    end.keys
+  end
+end
+
+p TxClient.new('canton7', '').list_translations