Created
February 4, 2014 22:31
-
-
Save scicco/8813700 to your computer and use it in GitHub Desktop.
get lang code from unix
This file contains 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
require 'fileutils' | |
counter = 1 | |
if File.exists?('/usr/share/i18n/SUPPORTED') | |
FileUtils.copy_file('/usr/share/i18n/SUPPORTED','/tmp/lang_list.txt') unless File.exists?('/tmp/lang_list.txt') | |
file = File.open("/tmp/lang_list.txt", "r") | |
file_export = File.new("/tmp/lang_export.txt", "w+") | |
lang_set = Hash.new | |
output_list = "" | |
while (line = file.gets) | |
puts "#{counter}: #{line}" | |
output = '' | |
output = line.sub(/\s.*/,'') || line | |
output = output.sub(/\.[\w\d\-]*/,'') || output | |
output = output.sub(/\@[\w\d\-]*/,'') || output | |
if !lang_set.has_key?(output.to_sym) | |
lang_set[output.to_sym] = true | |
puts "adding #{output}" | |
output_list << "#{output}" | |
else | |
puts "skipping .." | |
end | |
counter = counter + 1 | |
end | |
file_export.write output_list | |
file.close | |
file_export.close | |
else | |
puts "/usr/share/i18n/SUPPORTED not found on your system" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment