Changeset 9

Show
Ignore:
Timestamp:
07/08/06 11:52:29 (6 years ago)
Author:
olivier
Message:

Added country names methods

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/init.rb

    r2 r9  
    22require 'globalize/db_translate_ex' 
    33require 'globalize/locale_ex' 
     4require 'globalize/action_view_ex' 
  • trunk/lib/globalize/locale_ex.rb

    r2 r9  
    44    @@countries_for_select = {} 
    55     
     6     
     7    # Change locale language during block execution. 
    68    def self.switch(locale) 
    79      cur_language_code = self.language_code 
     
    1113      result 
    1214    end 
     15     
     16    # return translated countries 
     17    def self.countries 
     18      # Translate and cache data. 
     19      if @@countries[self.language_code].nil? 
     20        @@countries[self.language_code] = COUNTRIES.collect{|c| c.t} 
     21      end 
     22      @@countries[self.language_code] 
     23    end 
     24     
     25    # return an [original country, translated country] 2d array 
     26    def self.countries_for_select() 
     27      if @@countries_for_select[self.language_code].nil? 
     28        @@countries_for_select[self.language_code] = [] 
     29        countries.each_index do |i| 
     30          @@countries_for_select[self.language_code] << [countries[i], COUNTRIES[i]] 
     31        end 
     32      end 
     33       
     34      @@countries_for_select[self.language_code] 
     35    end 
     36   
     37    private 
     38      COUNTRIES = [ "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", 
     39          "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia", 
     40          "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", 
     41          "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegowina", 
     42          "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", 
     43          "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burma", "Burundi", "Cambodia", 
     44          "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", 
     45          "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", 
     46          "Comoros", "Congo", "Congo, the Democratic Republic of the", "Cook Islands", 
     47          "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", 
     48          "Djibouti", "Dominica", "Dominican Republic", "East Timor", "Ecuador", "Egypt", 
     49          "El Salvador", "England", "Equatorial Guinea", "Eritrea", "Espana", "Estonia", 
     50          "Ethiopia", "Falkland Islands", "Faroe Islands", "Fiji", "Finland", "France", 
     51          "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Gambia", 
     52          "Georgia", "Germany", "Ghana", "Gibraltar", "Great Britain", "Greece", "Greenland", 
     53          "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", 
     54          "Haiti", "Heard and Mc Donald Islands", "Honduras", "Hong Kong", "Hungary", "Iceland", 
     55          "India", "Indonesia", "Ireland", "Israel", "Italy", "Iran", "Iraq", "Jamaica", "Japan", "Jordan", 
     56          "Kazakhstan", "Kenya", "Kiribati", "Korea, Republic of", "Korea (South)", "Kuwait", 
     57          "Kyrgyzstan", "Lao People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", 
     58          "Liberia", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia", 
     59          "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", 
     60          "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", 
     61          "Micronesia, Federated States of", "Moldova, Republic of", "Monaco", "Mongolia", 
     62          "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", 
     63          "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", 
     64          "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Ireland", 
     65          "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", 
     66          "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", 
     67          "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russia", "Rwanda", 
     68          "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines", 
     69          "Samoa (Independent)", "San Marino", "Sao Tome and Principe", "Saudi Arabia", 
     70          "Scotland", "Senegal", "Serbia and Montenegro", "Seychelles", "Sierra Leone", "Singapore", 
     71          "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", 
     72          "South Georgia and the South Sandwich Islands", "South Korea", "Spain", "Sri Lanka", 
     73          "St. Helena", "St. Pierre and Miquelon", "Suriname", "Svalbard and Jan Mayen Islands", 
     74          "Swaziland", "Sweden", "Switzerland", "Taiwan", "Tajikistan", "Tanzania", "Thailand", 
     75          "Togo", "Tokelau", "Tonga", "Trinidad", "Trinidad and Tobago", "Tunisia", "Turkey", 
     76          "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", 
     77          "United Arab Emirates", "United Kingdom", "United States", 
     78          "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", 
     79          "Vatican City State (Holy See)", "Venezuela", "Viet Nam", "Virgin Islands (British)", 
     80          "Virgin Islands (U.S.)", "Wales", "Wallis and Futuna Islands", "Western Sahara", 
     81          "Yemen", "Zambia", "Zimbabwe" ] unless const_defined?("COUNTRIES") 
    1382  end 
    1483end