Git Product home page Git Product logo

carmen's People

Contributors

aalin avatar aldesantis avatar alvatar avatar baldarn avatar bowsersenior avatar cdainmiller avatar ecbypi avatar envek avatar esad avatar grobie avatar j15e avatar jacortinas avatar jasonbarnabe avatar jcsky avatar jim avatar kagetsuki avatar kainio avatar liwh avatar marjakapyaho avatar matsubo avatar namxam avatar olleolleolle avatar pajk avatar petergoldstein avatar prathe avatar sharnik avatar swcraig avatar vlado avatar yehezkielbs avatar ynurmahomed avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

carmen's Issues

Appended data paths require files for all regions to be present

The comment for Carmen::Region#load_data_at_path says:

The resulting data will be the result of loading the file from the data_path and overlaying matching data (if it exists) from the overlay_path.

According to this, the path should not be loaded unless it exists, but this isn't currently happening.

I've done this:

Carmen.append_data_path Rails.root.join('config')

And added files at config/world.yml and config/world/us.yml, which works fine for the US, but now when fetching the subregions for other countries, I get an error like this:

Errno::ENOENT: No such file or directory - /app/config/world/gb.yml

Additionally, I don't actually need a world.yml file in this case, but without it I get:

Errno::ENOENT: No such file or directory - /app/config/world.yml

Names of states for India are incorrect

I'm not sure where the state names for India came from, but the typical and common English names used in all correspondence (addresses, government documents, etc.) do not use names like Himāchal Pradesh, Mahārāshtra or Damān and Diu (note the accented ā characters). The name in such cases use the "normal" non-accented characters such as in Himachal Pradesh, Maharashtra and Daman and Diu.

Ps. The Wikipedia article at http://en.wikipedia.org/wiki/States_and_territories_of_India contains the correct names as of today.

Ps. I am referring to the list of states in the iso_data/world/in.yml file.

Bug(s)

You have a bug in your code:

      priority_countries = Carmen::COUNTRIES.select do |country, code|
        priority_country_codes.include?(code)
      end

Array#select passes just ONE argument to the block, so code (that you are using in the block) will never get defined.

To achieve the same intended result, I would suggest:

  priority_countries = priority_country_codes.map do |code|
     Carmen::COUNTRIES.rassoc code
  end

Besides:
return country_options + options_for_select(Carmen::COUNTRIES, priority_country_codes.include?(selected) ? nil : selected)

How that is supposed to wok? It will set select thhe country only in case of a priority country? That's too bad when you have to use the form for an update: it will not show the correct selected value if the selected country is not included in the priority countries!

Regards

Carmen.overlay_path error: undefined method

Hi Jim,

I'd like to add additional subregions for the USA, and I figured the correct way of accomplishing this would be the overlay_path feature.

'AA' => 'Armed Forces Americas', 'AE' => 'Armed Forces Europe', 'AP' => 'Armed Forces Pacific'

However, it looks like overlay_path is not defined and I didn't find it anywhere in the gem code. Is this an old feature from 0.2?

1.9.3p194 :009 > Carmen.overlay_path = File.expand_path('../my_data', FILE)
NoMethodError: undefined method overlay_path=' for Carmen:Module from (irb):9 from /Users/***/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:47:instart'
from /Users/**_/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in start' from /Users/**_/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:41:in <top (required)>'
from script/rails:6:inrequire' from script/rails:6:in

'

Help is much appreciated.

Thanks,
-Manuel

When is next version due for release?

Hi,

I love the Carmen gem! Thanks for this.
I got a complaint from a customer in Taiwan that their country is listed as "Taiwan, Province of China". Bit of a political hot potato apparently.
I notice this has been changed in the Master branch's en.yml file, just to "Taiwan".
But the latest gem version is still at 0.2.8.

So my question is how soon till the next version release, so that this change will be available through bundle update???

Thanks,

Richard

Sort options by country-names

Hi,

Onto now the options in country_select are sorted by their codes. Is it possbile to sort by the states' names? it is a better usability in my opinion.

thank you

country_select priority not working?

Hi, maybe I have the syntax wrong, but I could've sworn it was working before:

<%= profile_form.country_select :country, ["CA", "US"] %>

This just outputs the full list normally, without the values prioritized up at the top.

typo of Japanese translation file.

I believe 'locale/jp/world.yml' file (/directory) should be 'locale/ja/world.yml'.
and 2nd line of this file also should be fixed too.

thanks.

Don't use regular expression/fuzzy matching unless specifically requested

It seems like by default if you feed it bad data, it should respond with nil or an error, rather than with bad data. For example:

irb -> Carmen::country_name(Carmen::country_code('US'))
    => "Australia"

How about only using fuzzy matching if they pass in an option like :fuzzy => true?

irb -> Carmen::country_name(Carmen::country_code('aust', :fuzzy => true))
    => "Australia"

irb -> Carmen::country_name(Carmen::country_code('stria', :fuzzy => true))
    => "Austria"

But:

irb -> Carmen::country_name(Carmen::country_code('US'))
    => nil

country select no longer works??!

I have just started getting errors with the country select form helper. it seems that it is still trying to use the Carmen::COUNTRIES constant? It looks like you're trying to break the helpers out into a separate gem, what is the status on that?

Norway's country code converted to boolean false

I think the country code needs to be wrapped in quotation marks inside countries.yml.
NO ---> 'NO'

in the countries.yml file:
- - Norway
- NO

in irb:
irb(main):001:0> require 'vendor/plugins/carmen/lib/carmen.rb'
=> true
irb(main):002:0> Carmen.country_code('Norway')
=> false
irb(main):003:0> Carmen.country_code('Oman')
=> "OM"

Could not load countries for 'es' locale

Hi,

Do we need to copy the localization files?
Carmen.default_locale = :es causes the error "Could not load countries for 'es' locale"
English is ok but not others.

I can see the locale files in the project but do we need to copy them manually? Where?

Thanks.

mixed language/country codes in locale directory

(this issue related to issue #100 )

in the directory of /locale in carmen, there are 2-letter code directories for each languages. (I guess they are languages and not countries. fix me if I am wrong.)
but some of directory names are country code, not language code.

so far country codes are 'China' & 'Japan'. they should be 'Chinese' & 'Japanese'. ('zh' & 'ja')

list of names in /locale directory.

  • cn:country 'China' (lang = zh )
  • cs:lang 'Czech'
  • de:lang/country 'German/Germany'
  • en:lang 'English'
  • es:lang/country 'Spanish; Castilian/Spain'
  • fi:lang/country 'Finnish/Finland'
  • fr:lang/country 'French/France'
  • hi:lang 'Hindi'
  • it:lang/country 'Italian/Italy'
  • jp:country 'Japan' (lang = ja)
  • ko:lang 'Korean'
  • nl:lang/country 'Dutch/Netherlands'
  • pl:lang/country 'Polish/Poland'
  • pt:lang/country 'Portuguese/Portugal'
  • ru:lang/country 'Russian/Russian Federation'
  • sk:lang/country 'Slovak/Slovakia'
  • sv:lang(/country) 'Swedish(/El Salvador)'
  • tr:lang/country 'Turkish/Turkey'

ref.
language tag ISO-639-1
http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
country code ISO-3166-1
http://en.wikipedia.org/wiki/ISO_3166-1

Allow more granular datasets

Right now Carmen can only support countries and a single level of child states. There are places in the world where this 2-level design doesn't really work.

Version 2 should have a refined API that can handle a variable number of levels, as well as a data format that is flexible enough to store this data.

custom locale

im wondering if there is a way to load a custom yml file from within my app, rather than add it to /data/countries, or without forking and installing it as a plugin. can i initialize a locale file from /locales?

state_codes returning NoMethodError

i tried to fetch state_codes for a country that has no state:
Carmen::state_codes('ID')
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map
from /home/dimas/Rails/my_app/vendor/plugins/carmen/lib/carmen.rb:68:in `state_codes'
from (irb):17
from :0

Is it better to return nil or an empty array??

Regards,
Dimas Priyanto

state_select issue with Ontario

Im using Carmen to build a state_select for Canada and for some reason the output options is setting the value to "true" for Ontario instead of using the "ON" code.

I have worked around this by changing the code in the ca.yml file for Ontario to ONT and it seems to work fine.

Country aliases/synonyms ("Vietnam" for "Viet Nam")?

Sometimes a country is commonly referred to by names other than the name officially assigned by ISO 3166.

This presents a problem when you are trying to automatically interpret user-supplied data as I am trying to do. Users don't know or care which name ISO 3166 deems "official" -- they may have other ideas about the correct name for a country.

Case in point: Vietnam. ISO 3166 seems to have assigned it the name "Viet Nam" but I think it is more commonly known as "Vietnam". Even with the regular expression searching currently done by Carmen::country_code, the lookup fails for this case:

irb -> Carmen::country_code('Vietnam')
    => nil

— which of course surprised me, that it wouldn't recognize this well-known country name.

I've worked around this problem in my own code by creating a very simple country synonym checking method, but I'm hoping that official support for aliases/synonyms could be added (or some other solution that solves this problem :))...

Interesting to note:

Compiled Templates

In my view, I have this:
<%= f.collection_select :modelo, Carmen::COUNTRIES, {}, { :onchange => "change_state_select(this.options[this.selectedIndex].value);" }%>
And I received this error message:
uninitialized constant ActionView::Base::CompiledTemplates::Carmen

I've used gem version 0.1.1, rails is 2.3.9 and ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]

Disable APO States

Is there a way to disable APO states? All I need is to have the 50 US States and DC.

Carmen.i18n_backend.append_locale_paths ('../locale_ext') - NoMethodError

Hi Jim,

I was unable to set a customized locale path with the provided instructions because I got an NoMethodError. After a little digging I noticed that the i18n_backend call returned a string. So I set the i18n_backend variable manually in the console and I got it to work (see caputres below). I could accomplish the same when executing Carmen.reset_i18n_backend.

However, when I try either method in the application.rb file, the i18n_backend value always returns a string and rails quits with an NoMethodError.

Do I have the code in the wrong place? Any idea what's going on here?

Thanks!

application.rb

require "carmen"
include Carmen
Carmen.append_data_path File.expand_path('../iso_data_ext', __FILE__)

Console

1.9.3p194 :001 > Carmen.i18n_backend.append_locale_path ('../locale_ext')
NoMethodError: undefined method `append_locale_path' for I18n:Module
    from (irb):1
    from /Users/***/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
    from /Users/***/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
    from /Users/***/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
1.9.3p194 :002 > Carmen.i18n_backend.inspect
 => "I18n" 
1.9.3p194 :003 > Carmen.i18n_backend= Carmen::I18n::Simple.new
 => <#Carmen::I18n::Simple locale=en> 
1.9.3p194 :004 > Carmen.i18n_backend.append_locale_path ('../locale_ext')
 => [#<Pathname:../locale_ext>] 

NoMethodError: undefined method `downcase' for false:FalseClass

I've been seeing this error quite a lot in production. I'm verifying that the state code isn't nil or false before passing it to carmen.

[GEM_ROOT]/gems/carmen-0.2.8/lib/carmen.rb:149:in block in search_collection' [GEM_ROOT]/gems/carmen-0.2.8/lib/carmen.rb:148:ineach'
[GEM_ROOT]/gems/carmen-0.2.8/lib/carmen.rb:148:in search_collection' [GEM_ROOT]/gems/carmen-0.2.8/lib/carmen.rb:97:instate_name'
app/models/trace.rb:91:in `find_state'

Two-letter codes not unique

Alberta, British Columbia, South Carolina are all problematic.

Carmen::state_name('BC')
=> nil
Carmen::state_name('MA')
=> "Massachusetts"
Carmen::state_name('AB')
=> nil

Not sure how state_name is supposed to be used if so many examples return bad results.

Misspelling of a Brazilian State

The Brazilian State "Minas Geraís" is currently misspelled and should be "Minas Gerais" without the accent on the 'i'.

Cheers!

How to display only a few countries

Hey Jim,

I have been trying to acheive this for a long time but have already wasted a lot of effort. Hoping that you may help me here.

I have the following line in my view:

<%= f.country_select :country, {priority: %w(US CA), prompt: 'Please select a country'}, {:id => "contact_country"} %>

Now, I want to actually just show 2 countries, USA and Canada and nothing else.

How do I limit the number of countries to show. Can you please gimme some example code. I have seen someone saying Carmen.excluded_countries = Carmen.countries - ['US', 'CA']

but I am afraid that is not solving my problem, as I am not sure where to set this. If I do this in initlizer of my application, I am getting error:

undefined method `excluded_countries=' for Carmen:Module (NoMethodError)

Please help me achieving this.

Thanks in advance ..

"Invalid gemspec" error

When trying to install the gem, getting the error below:

"Installing carmen (0.2.9) Invalid gemspec in [/Users/soccerswim8/.bundler/tmp/26979/specifications/carmen-0.2.9.gemspec]: Illformed requirement ["#Syck::DefaultKey:0x0000010678bc28 1.6.2"]"

Help? Thanks!

state_codes throws an exception for countries with no states

I am doing some custom validation on my address object to ensure no asshattery with invalid regions, as follows. Note that I am manually rescuing the state_codes call as it will bomb if a country with no states is passed in.

def valid_state
state_codes = Carmen::state_codes(country_code || Carmen::default_country) rescue []
errors.add(:state_code, :blank) if state_code.blank? && !state_codes.blank?
errors.add(:state_code, :inclusion) unless state_codes.blank? || state_codes.include?(state_code)
end

Duplicate countries when excluding and prioritizing

In v0.2.x, when you exclude countries and prioritize countries, the prioritized countries are duplicated. Eg:

# Exclude everything except Canada, America, and Mexico.
Carmen.excluded_countries = Carmen.countries.map do |c|
  ["Canada", "United States", "Mexico"].include?(c.first) ? nil : c.last
end.compact

Carmen.countries
=> [["Canada", "CA"], ["Mexico", "MX"], ["United States", "US"]]

Carmen.priority_countries = %w(US CA)

Carmen.countries
=> [["United States", "US"], ["Canada", "CA"], ["Canada", "CA"], ["Mexico", "MX"], ["United States", "US"]]

Problem with 0.2.10 gem

When upgrading to use the 0.2.10 version of the gem I get an error that "carmen/country" is missing. Looking at the gem source it seems as if 0.2.10 really is the master branch packaged using the Gemspecs for 0.2.x.

Show only some countries.

Hi,

We have a requirement to display in drop down only those countries where projects are already existing. For e.g. projects might be existing in only India, China and Afghanistan. So I'm running a query to get country_iso2 codes of India, China and Afghanistan from Projects table. Now I've to show the dropdown of these 3 countries.

How can I leverage Carmen.countries to show only 3 countries? Is there such an option? How can I tweak below select to show only India, China, Afghanistan

= select(:filter, :country_iso2, Carmen.countries, :id => "profile_country", :selected => @country_iso2)

Taiwan, Province of China -> Taiwan

Hi,

Some visitors of my website sent me an email to complain about the text used for "Taiwan, Province of China". Could you replace it by "Taiwan"?

Thank you

"Illformed requirement" error message on install

Hi,

I can' t install Carmen gem without having this error message :

WARNING:  #<ArgumentError: Illformed requirement ["#<Syck::DefaultKey:0x00000109609488> 1.6.2"]>
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
  s.name = %q{carmen}
  s.version = "0.2.9"

  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
  s.authors = ["Jim Benton"]
  s.date = %q{2011-12-20 00:00:00.000000000Z}
  s.description = %q{A collection of geographic country and state names for Ruby. Also includes replacements for Rails' country_select and state_select plugins}
  s.email = %q{[email protected]}
  s.extra_rdoc_files = ["README.rdoc"]
  s.files = ["CHANGELOG.md", "Gemfile", "MIT-LICENSE", "README.rdoc", "Rakefile", "VERSION", "carmen.gemspec", "data/countries/cn.yml", "data/countries/cs.yml", "data/countries/de.yml", "data/countries/en.yml", "data/countries/es.yml", "data/countries/fi.yml", "data/countries/hi.yml", "data/countries/it.yml", "data/countries/jp.yml", "data/countries/nl.yml", "data/countries/pl.yml", "data/countries/pt.yml", "data/countries/ru.yml", "data/countries/sk.yml", "data/countries/sv.yml", "data/states/au.yml", "data/states/br.yml", "data/states/ca.yml", "data/states/cu.yml", "data/states/de.yml", "data/states/dk.yml", "data/states/es.yml", "data/states/hr.yml", "data/states/in.yml", "data/states/it.yml", "data/states/mx.yml", "data/states/nl.yml", "data/states/no.yml", "data/states/nz.yml", "data/states/ua.yml", "data/states/us.yml", "lib/carmen.rb", "lib/carmen/action_view_helpers.rb", "lib/carmen/railtie.rb", "test/carmen_test.rb", "test/carmen_view_helper_test.rb", "test/test_helper.rb"]
  s.homepage = %q{http://github.com/jim/carmen}
  s.require_paths = ["lib"]
  s.rubygems_version = %q{1.3.7}
  s.summary = %q{A collection of geographic country and state names for Ruby}

  if s.respond_to? :specification_version then
    current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
    s.specification_version = 3

    if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
      s.add_development_dependency(%q<jeweler>, ["#<Syck::DefaultKey:0x00000109609488> 1.6.2"])
      s.add_development_dependency(%q<mocha>, [">= 0"])
      s.add_development_dependency(%q<rails>, [">= 0"])
      s.add_development_dependency(%q<hanna>, [">= 0"])
    else
      s.add_dependency(%q<jeweler>, ["#<Syck::DefaultKey:0x00000109609488> 1.6.2"])
      s.add_dependency(%q<mocha>, [">= 0"])
      s.add_dependency(%q<rails>, [">= 0"])
      s.add_dependency(%q<hanna>, [">= 0"])
    end
  else
    s.add_dependency(%q<jeweler>, ["#<Syck::DefaultKey:0x00000109609488> 1.6.2"])
    s.add_dependency(%q<mocha>, [">= 0"])
    s.add_dependency(%q<rails>, [">= 0"])
    s.add_dependency(%q<hanna>, [">= 0"])
  end
end
WARNING:  Invalid .gemspec format in '/Users/francois/.rvm/gems/ruby-1.9.2-p0@docendi/specifications/carmen-0.2.9.gemspec'

With or without Bundler, no differences.
Version 0.2.8 or 0.2.9 produce the same errors.

Any ideas ?

Thx a lot.

default_locale has no fallback

When I set Carmen.default_locale to a non existant locale, the application throws an exception.
Instead it should fall back to the gem default. English.

Second, it would be great if there were some specs and tests about the behavior of default_locale.

It would be even better if the default would be always I18n.locale which keeps the current language used in a typical rails application.

Currently, I set carmen's default_locale with this:
I bet there is a better way :)

    # Set default locale for carmen gem
    # Shall be revised in later version.
    available_carmen = [:cn, :cs, :de, :en, :es, :fi, :hi, :it, :jp, :nl, :pl, :pt, :ru, :sk, :sv]
    carmen_locale = available.select { |locale| locale == I18n.locale }.first
    carmen_locale && Carmen.default_locale = carmen_locale

HTML options.

Is there a way to pass html_options like

f.country_select(:country_code, priority: %w(US CA), prompt: 'Please select a country', { :class => 'my_style_class' })

or like rails use select fields

f.country_select(:country_code, priority: %w(US CA), prompt: 'Please select a country', {}, { :class => 'my_style_class' })

I try to style my country_select for twitter bootstrap (eg: span2 class for a smaller version)

thanks for your response. :-)

Error on jo.yml

Hi

I get error on bundler/gems/carmen-10cf4393c360/locale/en/world/jo.yml
Error message ActionView::Template::Error: couldn't parse YAML at line 6 column 14

I'm working on Ubuntu 11.11, ruby 1.9.2-p290 and Rails 3.2.1

Unsupported locale

I saw that there are locale such as es etc already available. but when tried are not available!! Could be a quick fix...

Thanks,
Munjal

RegexpError: '\' can't be last character

Searching for state_code or country_name of string ending with '' raises an exception e.g.

>> Carmen.state_code 'alabama\\'
RegexpError: invalid regular expression; '\' can't be last character: /alabama\/
    from /Library/Ruby/Gems/1.8/gems/carmen-0.2.8/lib/carmen.rb:153:in `match'

Carmen::Querying::named case-sensitivity

Hi, Jim.

I’m in the process of upgrading our application which very successfully uses Carmen 0.2.12 to 1.0.0b2 (and I will probably have some pull requests forthcoming), and I quite accidentally stumbled upon (yay unit tests) the fact that Carmen::Querying::named is case sensitive, where the 0.2.x methods were not.

I suspect this is because case-folding Unicode characters is a tricky business.

The unicode_utils gem could help greatly with this, but it is limited to Ruby 1.9, and I wanted to talk to you about the issue before I submitted a pull request that adds a gem dependency.

What are your thoughts on the matter?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.