The attached patch adds the ability for users to set the default country for a site. This can be set during the installation process and can be later modified at admin/settings/site-information.

This feature would be useful in a few different ways. It would be a first step towards providing country specific date and number formats. While an individual site can set its own default date format in Drupal core and number format (via contrib), it would be better to pre-determine this based on country/language information, rather than requiring each site to make these changes manually.

In enabling localizing of formats, we have two options. One is to require country-specific language codes, e.g. fr-CA, for locale-appropriate handling of data like date and number information. For example, date handling in French Canada may be different both from that of France and from that of English Canada. So being able to configure a date / number format per 2-character language ('fr') isn't sufficient. While some sites may choose to install and enable such custom 5-character languages (using country code module), most will not. Those that do will also lose automatic import of all 'fr' translations.

Which brings us to option two, which is what we're proposing here - introduce a country, and consult that as well as language to determine the appropriate localized format.

The location module already implements a default country setting, but is only used to initialize the country in drop-down lists. Modules wishing to implement locale-appropriate date formats (Date) or number formats (Format Number) will not want to create a dependency on such a large module for which the majority of the features will not be required. This could lead to duplication of the setting amongst contrib whereas ideally I think it should be set in core.

Catch also suggested that it might be a useful follow-on patch for #11077: Introduce Daylight Saving Time for Drupal as a way to shorten the long list of time zones.

Cheers,
Stella

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Damien Tournoud’s picture

Well, I would really much like that we rework the date and time page into a full featured "regional settings" page, including country, default time zone, number formats and currency. This is a first step in that direction, but we should think about it a little bit more.

stella’s picture

FileSize
11.54 KB

Updated patch.

Status: Needs review » Needs work

The last submitted patch failed testing.

stella’s picture

Status: Needs work » Needs review

failure was due to HEAD not installing properly

catch’s picture

Damien's plan seems like a good one, at least long term, will take a proper look at this patch later.

catch’s picture

Status: Needs review » Needs work

So while this patch looks like a lot of code due to the include (which is only loaded on one settings form), it just adds two forms - one to the installer, one to a settings page for default country. There's a @TODO for drupal_alter() in there - we should add that, and also hook documentation now that system.api.php is available to patch against.

Would it be too much to change 'date and time' to regional settings, and add the form as a fieldset there? We could still mention date/timezone settings in the description on the admin index.

stella’s picture

Status: Needs work » Needs review
FileSize
18.83 KB

I've updated the patch with the changes suggested. I've added in the call to drupal_alter() on the countries list. I also moved the "default country" form element to the "date and time" form and renamed that form to "regional settings". I also changed the URL to match.

Cheers,
Stella

flickerfly’s picture

I tested the patch in #7. Improving drupal's intelligence in this area is a great idea.

On the install, could we choose the country a bit more intelligently like we do the time zone, at least choose a country in the timezone chosen?

It seems to have worked in the regional settings menu.

I would prefer to see this connected to the 5-character so that you have more information (country and language).

KarenS’s picture

There's no way to choose a country in the timezone unless we have some code that maps countries to timezones, and I don't know of any easy way to do that. But we can map continents to timezones, since the continent name is in the timezone name.

I'm wondering if the country list should be in the db instead of an array so we can add additional information to it. For instance we could add a column for 'continent' to each country relatively easy, then use the continent of the selected country to reduce the size of the available timezone list, or use the continent of the timezone to reduce the size of the country list.

We could also later add columns for the official languages for each country to reduce the size of a language list, or limit the country list to only countries that support a given language.

All of those things are only feasible if we store this info in the db instead of a hard-coded array.

Dries’s picture

Slightly off-topic. For the language codes (not country codes!), I think we need to move from ISO 639-1 to ISO 639-2. On Mollom.com, we could not use Drupal's built-in language list, but had to use our own ISO-639-2 list because it is more complete. I know this isn't the same as the country list proposed in this patch, but I figured I'd bring this up because there might be interplay between these different ISO standards. Anyway, might be useful to create an iso.inc instead of a country.inc which includes both.

Dries’s picture

PS: I'm OK to go with hard-coded lists for now.

stella’s picture

Some countries lie within more than one timezone, so we'd need to keep that in mind if associating a default timezone with any one particular country.

However, I do like the idea of the timezone list updating when the country setting is changed. It will require a bit of AJAX to implement, but I don't think it'll be too difficult. Will work on this over the next few days and post a revised patch.

Cheers,
Stella

stella’s picture

Status: Needs review » Needs work
stella’s picture

Ok here's a slightly modified patch. The only difference is that both the list of countries and the list of languages are in one iso.inc file as Dries suggested.

I looked into the automatic setting of the timezone based on the selected country. The AJAX involved is fairly simple. However, as KarenS mentioned, the difficulty arises in determining the timezone(s) for a particular country, and vice versa. There's no PHP function currently available that allows us to do that - though it does appear that this will be available in PHP 5.3 which is due to be released later this year. See timezone_identifiers_list() (country specifier not available yet), and timezone_location_get().

So short of waiting for PHP 5.3 stable release and making Drupal 7.x dependant on that, we'd have to add a list of timezones and their abbreviations to the iso.inc file. We'd need to associate each timezone with a country too. KarenS suggested storing this information in a database table, which might be the way to go - it would allow the greatest flexibility and we could add in language suggestions too. However, when php 5.3 is released, we may not need to store the timezones any more. Also we should keep in mind that timezones can change, and I think are one or two changes a year. KarenS's option of associating a continent with each country would be easier (either in db or .inc file) and they definitely don't change as often.

Which option do people prefer? I can easily re-roll the patch again to reflect whatever is decided.

Cheers,
Stella

stella’s picture

Status: Needs work » Needs review
FileSize
20.96 KB

Oops, this time with patch attached.

Status: Needs review » Needs work

The last submitted patch failed testing.

stella’s picture

Status: Needs work » Needs review
FileSize
36.48 KB

Patch re-roll, forgot to include the iso.inc file.

catch’s picture

Patch works well, a few questions though:

Why are the countries using $t() but the languages not?

While I like the 'regional settings' page, I'm now wondering wether we want the actual date presentation settings on there - since they're not really tied to localisation at all. It might possibly make them hard to find for people who just want to change whether their site uses Wednesday or We. Short of a separate admin/settings/date page with just those settings on, I'm not sure where else they can go though.

nedjo’s picture

Issue tags: +i18n sprint
stella’s picture

I didn't include the languages in $t() since it was that way already in Drupal core. I imagine this is something to do with the native language string appearing in parentheses after the English string for some languages. I agree that the language should be translated, but I think only the first item in the array() for each language should be enclosed in t() - because if I understand correctly, the subsequent array items are already translated to that particular language. What do others think?

I think having the date settings on the regional settings page is ok and would be in favour in having both of these together rather than on separate pages.

c960657’s picture

+  $items['admin/settings/regional-settings'] = array(
+    'title' => 'Regional settings',
     'description' => "Settings for how Drupal displays date and time, as well as the system's default time zone.",
     'page callback' => 'drupal_get_form',
     'page arguments' => array('system_date_time_settings'),

I suggest you rename system_date_time_settings() to system_regional_settings() to match the menu patch.

-    '#description' => t('Select the default site time zone.')
+    '#description' => t('Your time zone setting will be automatically detected if possible. Please confirm the selection and click save.'),
+    '#attributes' => array('class' => 'country-timezone-detect'),

What's the purpose of that class? There is currently no magic connected with country-timezone-detect. There is with timezone-detect, though, but that will make the auto-detection overwrite the previous value, every time the page is loaded. The timezone is set during the install and when upgrading from D6 (I think), so there is usuallly no reason to do auto-detection here.

iso.inc seems like a very general name. ISO standardized lots of stuff. On the other hand, iso.inc may be a good place for any kind of list that is derived from an ISO standard.

+ * in ISO 3166-1 alpha-2 with the exception that on the ISO standard
+ * country codes are uppercased.

Why not use upper-case like in the official standard?

The list misses two country codes that were assigned in 2007 (mentioned in the Wikipedia article on ISO 3166-1):

  • BL: Saint Barthélemy
  • MF: Saint Martin (French part)
Dries’s picture

Status: Needs review » Needs work

Let's go with the generic iso.inc for now. We can decide to rename or split it up later when it becomes a problem.

The comments in #22 need to be tackled.

stella’s picture

Status: Needs work » Needs review
FileSize
37.06 KB

Re-rolled patch which addresses all of the issues identified in #22

c960657’s picture

Status: Needs review » Needs work
-    '#description' => t('Select the default site time zone.')
+    '#description' => t('Your time zone setting will be automatically detected if possible. Please confirm the selection and click save.'),

This looks like a left-over from the earlier version of the patch. AFAICT there is no auto-detection on admin/settings/regional-settings. You may wish to change either the country or the timezone description, though, so they use the same phrasing, either “Select the default XXX for the site” or “Select the default site XXX”. I suggest you add a brief mention of what the default country is used for (for sites with an international audience it may not be obvious what the “default country” is).

If the user does not select a country but just clicks Save configuration, site_default_country is set to AF (Afghanistan), because it is the first country in the list. This seems like an odd default. I wonder whether there should be a dummy “no country” option at the top of the list. If the country is to be used for date formatting etc. there need to be some default, so perhaps it is better to add a default, e.g. US to match that the default UI language is American English.

stella’s picture

Status: Needs work » Needs review
FileSize
37.15 KB

Patch re-roll. The #description thing was left over from an earlier patch. I've also added a 'Please select a country' to the option list.

Dries’s picture

"No default country" is different than "Please select a country". In some cases, it might not make sense to have a default. Drupal.org would be a good example of where it might be better not to have a default.

stella’s picture

FileSize
37.26 KB

Re-rolled patch with that change.

xmacinfo’s picture

I’ve installed this patch and tried to see it’s benefit. I live in Canada where we have many time zones, two official languages, too many ways to write the dates and numbers, etc.

Although I was able to set the Default country, I do not see any interaction between the Country selection and any other Drupal site configuration. Are there other configurations and patches to be added later?

This patch works well though and can be comitted, but I don't see why we need this patch.

For example, Drupal ships with a single language, so setting the country would not change the language of the installation, but only set a flag for the user to download the language file later. Also selecting a country could offer default languages from a smaller selection, but what about country communities in other languages? A language affects the date format, so setting a Drupal site to a particular language should set the proper date format. But what if the user want to display the ISO date format?

There are some benefits, though, to set the Default country in Drupal:

  • Show only the time zones for this country.
  • Offer a choice of the default languages of the country, which would need to be downloaded (or automatically downloaded) later.
  • Set the various default date formats, based one the languages selected or use the ISO date format.
  • Set the number format, based on the country language.

Setting defaults is fine. But how far can we go and still let the user override settings?

stella’s picture

This patch is just a first step towards supporting country specific date and number formats. It doesn't provide any per-country functionality (yet), but the idea is that in the future, both core and contrib modules can add country-specific features without each module defining their own method to configure the default country for the site.

If this patch is committed, then we can start adding features like localizable date and number formats, and country-specific language codes. I've already created a patch for the date module (D6) that enables localizable date formats (I think this is committed, but not released yet), but has a dependency on the 'site default country' and 'country code' modules if country+language date formats are required. This patch alone would remove the need for the 'site default country' module dependency. There is also a patch waiting review against the locale module, #347351: Enable translation fallbacks, which is needed if we want to support language specific and language + country specific translations.

I looked into making the timezone automatically update depending on the country selected. There are a couple of barriers to doing this: (a) some countries have more than one timezone - still do-able though, and (b) to retrieve a list of timezones by country in php, you need PHP 5.3 which is still in beta. This is something I intend on taking another go at once a stable PHP 5.3 is released.

As well as being a first step towards supporting country specific date and number formats, and other translations, this patch should also help prevent duplication of the site country setting amongst contrib modules (e.g. 'site default country', 'location', etc), whereas ideally I think it should be set in core.

Cheers,
Stella

xmacinfo’s picture

Status: Needs review » Reviewed & tested by the community

As I stated earlier, this patch works, so RTBC.

However, on a larger view, all defaults must be over-ridable by the site administrator. Let's say that by default we setup a Canadian web site:

1. By default, the Canada setting sets the language to English. No need to add French since the default value is valid. The admin would be able to add French later. And for that matter, an Italian community in Canada would be able to set it's site in Italian.
2. By default, the Canada setting set the date format to Canadian English. No need to add French date format since the default value is valid. The administrator would be able to configure another date format later, and even configure it to use the international ISO date format.
3. By default, the Canada setting sets the time zone to Ottawa, which is the capital. No need to add any other time zone since the default value is valid. The admin would be able to change the time zone later and still let user adjust their own time zone.
4. By default, the Canada setting sets the number format to "$x,xxx.xx". No need to add the French Canadian number format since the first one is valid for Canada. The admin would later be able to change the number format to "x xxx,xx $" to make it French Canadian compliant.
5. For e-commerce modules (if we want to extrapolate), the Canada settings sets the tax tables to GST and PST by default. The admin then need to choose which province to set for the PST.

So like I said, even if we try to set as much default values as possible, each setting must be over-ridable. So, in my opinion, all these default setting are of no use.

The only setting that I think are important are:
1. language setting (and auto import), complete with 5 characters language code (fr-CA, en-CA, etc.).
2. time zone, which should default to the capital city of any country.

I'll be available to check on other issues related to this patch and see what comes of it.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Thanks stella! Good input from xmacinfo in the latest comment -- certainly something to work on. I went ahead and committed this patch to CVS HEAD. Let's address the other issues in follow-up patches. :)

Status: Fixed » Closed (fixed)
Issue tags: -i18n sprint

Automatically closed -- issue fixed for 2 weeks with no activity.