README.md in world-flags-0.2.7 vs README.md in world-flags-0.3.0

- old
+ new

@@ -25,10 +25,12 @@ ```javascript $("li.flag['data-cc'=dk).addClass('semi'); $("li.flag['data-cc'=dk).removeClass('semi'); ``` +CSS configuration in `application.css` manifest. + ```css */ *= require_self *= require_tree . *= require flags/flags32 @@ -58,26 +60,29 @@ = use_flags 32 ``` ## Configuring localization +You can run the Rails generator `world_flags:init` in order to create a basic initializer file for world flags with an overview of the different options available. + You can setup WorldFlags to use a localization map for the labels of the flag icons +```ruby WorldFlags.languages = some_language_hash # fx loaded from a yaml file WorldFlags.countries = some_country_hash # fx loaded from a yaml file +``` -Notice that it is a locale code pointing to a map of ISO_3166-1_alpha-2 codes -to labels for that locale. +Notice that it is a locale code pointing to a map of *ISO_3166-1_alpha-2* codes to labels for that locale. ```ruby { :en => {:gb => 'English', :dk => 'Danish'} :da => {:gb => 'Engelsk', :dk => 'Dansk'} } ``` -An english translation file of country codes (in json format) can be found in app/config/country_codes. +An english translation file of country codes (in json format) can be found in `app/config/country_codes`. ```ruby cc_file_en = File.join(Rails.root, 'app/config/country_codes/iso-3166-2.en.json') country_codes_en = JSON.parse File.read(cc_file_en) WorldFlags.languages = country_codes_en @@ -89,15 +94,19 @@ WorldFlags::Language.en = country_codes_en ``` If you use this approach, you must currently add a WorldFlags::Language class method for that locale (fx a method `#da`for danish) or fx use `attr_accessor :da`. For this approach, you must also set the active locales using `#active_locales`. -``` +```ruby WorldFlags.active_locales = [:en, :da] WorldFlags::Language.da = country_codes_da ``` +To customize the locale to flag code map, use: + +`WorldFlags.locale_flag_map = some hash` + Please feel free to suggest or improve this locale/translation infrastructure! ## Rendering Flags will be rendered in HTML as: @@ -120,11 +129,11 @@ You can also use built in helper methods: ```haml = flag_list 16 do - = flags [:ar, :gb], :selected => :gb + = flags :ar, :gb, :selected => :gb ``` Alternatively ```haml @@ -137,15 +146,17 @@ ```haml = flag(:ar) + flag(:gb, :selected => flag_code(I18n.locale) ``` +You can also include the :with_semi => true option in order to have flags not selected displayed with the 'semi' class (semi-bright image) + For use with tooltips or similar js plguins, it can be useful to set the <li> title attribute: ```haml = flag_list 32 do - = flags [:ar, :br, :gb], :title => true + = flags :ar, :br, :gb, :title => true ``` The flag_title will render the following list item: ```html @@ -161,35 +172,41 @@ ``` To also get content rendered for the <li> ```haml - = flags [:ar, :br, :gb], :content => true + = flags :ar, :br, :gb, :content => true ``` Note: There is also a #flag_selected? helper, which is (and/or can be) used to determine if the flag to be drawn should have the "selected" class set) + +## Automatic flag selection + The auto-select feature is by default turned off, but can be turned on/off using: ```ruby WorldFlags.auto_select = true # or WorldFlags.auto_select! ``` +With this feature turned on, WorlfFlags will attempt to set the `selected` CSS class on whatever flag drawn that matches the current `I18n.locale`code. +If this doesn't work out for you, try to add a WorldFlags flag-to-locale code mapping for the locale. + ## Using localization You can specify whether to look up labels for the flags for either language or country and for which locale to look up the labels (see Configuring localization) Use danish (da) country labels ```haml = flag_list 32 do - = flags [:ar, :br, :gb], :country => :da + = flags :ar, :br, :gb, :country => :da ``` Use danish (da) language labels ```haml = flag_list 32 do - = flags [:ar, :br, :gb], :language => I18n.locale + = flags :ar, :br, :gb, :language => I18n.locale ``` Note: In the config folder there is now a json file with all the english ISO-3166-2 code translations ready for use. You can make similar locale files for other locales/languages. h## Get client country code (browser and geo)