Skip to content

Instantly share code, notes, and snippets.

@dmerrick
Created August 3, 2009 17:29
Show Gist options
  • Save dmerrick/160703 to your computer and use it in GitHub Desktop.
Save dmerrick/160703 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -wKU
require 'pp'
require 'open-uri'
# the page that holds the registry (updated often)
registry = 'http://www.iana.org/assignments/language-subtag-registry'
culture_codes = Hash.new('')
current = ""
skip_these = %w[%% Added Type Scope Suppress-Script Macrolanguage Deprecated Comments Preferred-Value Macrolanguage Prefix]
open(registry) do |file|
file.readlines.each do |line|
# skip the line if it holds data we dont care about
if skip_these.any? {|skip| line =~ /#{skip}/}
next
# save the culture code of the current locale
elsif line =~ /Subtag/
current = line.sub(/Subtag: /,'').chomp.to_sym
next
else
line.sub!(/Description: /,'')
culture_codes[current] += line
end
end
end
pp culture_codes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment