Skip to content

Instantly share code, notes, and snippets.

@waynegraham
Created July 24, 2020 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save waynegraham/114136e6af8ae55d42ecc32f5ec4110c to your computer and use it in GitHub Desktop.
Save waynegraham/114136e6af8ae55d42ecc32f5ec4110c to your computer and use it in GitHub Desktop.
Arabic Translation vs Transliteration
require 'dotenv'
require 'any_ascii'
require 'aws-sdk-translate'
Dotenv.load
class String
def is_western?
count('a-zA-Z') > 0
end
end
places = File.readlines('dlme-cho-spatial-values-unique.txt')
client = Aws::Translate::Client.new(
region: 'us-east-1'
)
places.each do |place|
t2 = AnyAscii.transliterate(place)
translation = ""
unless place.is_western?
translation = client.translate_text(
text: place,
source_language_code: 'ar',
target_language_code: 'en'
)
puts "Original: #{place} | Transliterated: #{t2} | Translated: #{translation['translated_text']}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment