META: Provide locale (regional) formats framework for automated translation of non textual data

Created on 18 November 2011, over 13 years ago
Updated 25 May 2025, 5 days ago

This issue is created in the hopes of opening up discussion on the implementation of a locale [regional] formats framework that could be used to collect and automatically format/convert non textual data such as measurements, dates, telephone numbers, etc. There are a number of modules that extend Drupal's multilingual capabilities but they function independently and often have limited implementation. Some of the standard formats that could be provided include (2 samples provided for brevity, there could be many):

  • Number formats: 1,000,000.00 vs. 1000000,00
  • Collation
  • Date Formats: MM/DD/YYYY vs. DD/MM/YYYY
  • Calender systems
  • First day of week (Monday, Saturday or Sunday)
  • Timezone
  • Units of measure:
    • Length: cm vs. inches
    • Dry mass: kilograms vs. pounds
    • Liquid volume: litres vs pints
    • many other units
  • Currencies: UK Pound vs. US Dollar
  • Telephone formats: (999) 999-9999
  • Dialing country codes: +011 44 for England
  • Postal codes: 99999-9999

I see this as a basic framework provided by core that can be extended by contrib modules. Core could be responsible for detecting and providing the end users locale in the form of a country code. This could be obtained from browser info, stored user profile preferences, and site defaults, maybe IP detection etc. Contrib modules could extend the locale info by providing formats for specific data stored in fields. e.g. A locale_date module would provide date formats used around the world keyed by country code. It would also provide a date field that uses the site default date format or user selectable date format for collecting the data and storing it. Finally the module would provide formatters that would detect end user country code and format the date appropriately.

Existing modules of interest

  • Format Number API provides a method to configure number formats (site default and user defined) with configurable decimal point and thousand separators. Currently only 6.x. Could be used to convert stored decimal/float values into locale based formatted numbers.
  • Formatted Number CCK provides cck input of numeric types where thousands separator and decimal point are inherited from the Format Number API module. Could be used to collect locale based formatted numbers and store them as standard decimal/float values
  • Measured Value Field provides CCK input of decimal/float values together with a unit of measure such as length -> cm. It also provides formatters that can convert the value to another unit and display it with the unit symbol or name.
  • Calendar Systems provides support for different calendar systems like Iranian , Jalali , Hijir , Hebrew etc. This support is currently limited to display and data entry for date fields and the back-end date is always Gregorian (Timestamp). 6.x & 7.x!
  • Country code Provide location-appropriate path and content handling based on user's country. 6.x - project halted due to core limitations?
  • Units API Converts between various weights and measurements using the International System of Units (SI).

Related posts

Documentation

Formatting numbers, dates/times, sizes and intervals with localization

Possible resources

Unicode

Unicode Common Locale Data Repository (CLDR) seems to have all the locale data we could want. Probably too much. Their Terms of Use seem to allow free use with allowances for modification so long as original copyright notices are included.

Here's a sample of some of the data for en_US:

<ldml>
  <identity>
    <language type="es"/>
    <territory type="US"/>
  </identity>
  <dates>
    <calendars>
      <calendar type="gregorian">
        <dateFormats>
          <dateFormatLength type="short">
            <dateFormat>
              <pattern>M/d/yy</pattern>
            </dateFormat>
          </dateFormatLength>
        </dateFormats>
        <timeFormats>
          <timeFormatLength type="full">
            <timeFormat>
              <pattern>h:mm:ss a zzzz</pattern>
            </timeFormat>
          </timeFormatLength>
        </timeFormats>
      </calendar>
    </calendars>
  </dates>
  <numbers>
    <currencies>
      <currency type="USD">
        <symbol>$</symbol>
      </currency>
    </currencies>
  </numbers>
</ldml>

PHP 5.3+ Internationalization Functions

Pretty much all of this is useful but here are some quick call outs to useful functions.

The floor is yours

What would you like to see in framework like this?
Have thoughts about how this should be implemented?
Any pitfalls to look out for?

Feature request
Status

Active

Version

11.0 🔥

Component

locale.module

Created by

🇺🇸United States tinker

Live updates comments and jobs are added and updated live.
  • D8MI

    (Drupal 8 Multilingual Initiative) is the tag used by the multilingual initiative to mark core issues (and some contributed module issues). For versions other than Drupal 8, use the i18n (Internationalization) tag on issues which involve or affect multilingual / multinational support. That is preferred over Translation.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇰Denmark ressa Copenhagen

    That's a great idea @jigaurus! I suggested in another (duplicate?) issue, to move it from Display page to the Field settings page, as en extra option:

    Perhaps move the "Thousand marker" and "Decimal marker" settings from the "Manage display" page (/admin/structure/types/manage/article/display) to the field settings page? (/admin/structure/types/manage/article/fields/node.article.field_number), and live together with similar setting options, such as prefix and suffix ?

    It could be an option the user can select, where either a global character is used, or a language specific. The current select options could be updated to this:

    Thousand marker

    • - None -
    • Decimal point
    • Comma
    • Space
    • Thin space
    • Default for display language <<< Add this option

    Decimal marker

    • Decimal point
    • Comma
    • Default for display language <<< Add this option
  • 🇨🇦Canada xmacinfo Canada

    Actually, the best location for locations goes in the Regional settings page:

    /admin/config/regional/settings

    …inside the Locale fieldset.

    At this point, the site is already set up and, even if the site is in English, regional localization can be applied.

    USA - English - Imperial measurements
    Canada - English - Metric measurements.

    So language settings != localization settings.

    See the macOS screenshot attached for inspiration.

    Finally, detaching language from localization givers more flexibility to the site owner. He may want to use a different set of number separators than what we would expect for his region.

  • 🇩🇪Germany rkoller Nürnberg, Germany

    re #61 META: Provide locale (regional) formats framework for automated translation of non textual data Active i agree, that adding an option for following the defaults for the display language for the thousand and decimal marker is a good idea. the only thing i might object is moving that setting into the field settings (if i understand the proposed resolution correctly). the fields settings is mainly about storage in the database, but those settings are about how thousand markers and decimal markers are presented in the frontend to the user. that way i guess the better choice would be to keep those two select fields where they currently are on the manage display page and simply add those options to the select lists (and set them as default)?

    re #62 META: Provide locale (regional) formats framework for automated translation of non textual data Active i completely agree and i wonder if aside adding those localization setting to /admin/config/regional/settings it would make sense or even be necessary to consider adding those settings to the user profile page as well. so a user is able to override the global localization settings.

  • 🇩🇰Denmark ressa Copenhagen

    Thanks for the feedback @xmacinfo and @rkoller. Placing the settings on the Regional settings page does sound like a better idea. The reason I suggested under Fields settings, is because prefix and suffix are also placed there, and they are all about presentation, right?

    (Perhaps prefix and suffix ought to be moved to the Display tab? :) ... That's for another issue.)

    I am still just a casual user of languages in Drupal, and don't know the details about language/locale, and don't have the larger picture of how it all ties together. But as long as I -- as a site builder -- can easily for each language, select from a drop-down settings, which results in for example thousand separator being dot (".") for Danish and (",") for English, and set a field display to use these localized separators depending on display language, that would work for me.

    And thanks for the image, a possible inspiration for format/number/localization set up for each language in Drupal, that would work well. And having the option of not using the normal defaults for a language would be a nice feature, and the ideal set up.

    So, it seems like these could be changes in the interface:

    • Set custom separators for each installed language (da, en, fr, etc.) as in the image from #62 (I do only see the default language on that page ...)
    • Allow setting which separator to use under Display (as it is currently) having the options "Decimal point", "Comma", etc. and then add >> "Default for display language"
  • 🇩🇰Denmark ressa Copenhagen

    I updated the Issue Summary Allow localizing of formatting on decimal fields Active , trying to summarize the latest comments here. Feel free to correct if anything is wrong, or unclear :)

    And great suggestion @rkoller about adding support for user profile page as well, which I included in the Issue Summary.

    .... or should parts of the Issue Summary from #2757111 (mainly "Proposed resolution", I guess) be moved to this issue, to keep it all in one place?

Production build 0.71.5 2024