Created
August 20, 2024 09:46
-
-
Save amkisko/02fbae7ce35c1e335d0d2f2a4a63eff5 to your computer and use it in GitHub Desktop.
ruby crowdin-api machine translation script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def crowdin_translate(sentence, from_locale, to_locale) | |
require "crowdin-api" | |
config = Data.define(:api_token, :organization_domain, :project_id, :mt_id).new( | |
api_token: ENV["CROWDIN_API_TOKEN"], | |
organization_domain: ENV["CROWDIN_ORGANIZATION_DOMAIN"], | |
project_id: ENV["CROWDIN_PROJECT_ID"], | |
mt_id: ENV["CROWDIN_MT_ID"] | |
) | |
client = Crowdin::Client.new do |crowdin| | |
crowdin.api_token = config.api_token | |
crowdin.organization_domain = config.organization_domain | |
crowdin.project_id = config.project_id | |
crowdin.enable_logger = false | |
end | |
# NOTE: to fetch mt_id use client.list_mts | |
client.translate_via_mt(config.mt_id, query: { | |
strings: [sentence], | |
sourceLanguageId: from_locale, | |
targetLanguageId: to_locale | |
}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment