cms icon indicating copy to clipboard operation
cms copied to clipboard

Translate default dictionaries

Open andjsch opened this issue 1 year ago • 1 comments

Bug description

Currently, if you view the CP in another language and use one of the predefined dictionaries, the labels are not translated. I think translating Countries and Currencies would be sufficient enough.

If this is something that would be considered for a merge, I'd be happy to provide a PR.

For the PR, it should be considered where to put the translations.

  • Either within the {lang}.json file, which would be convenient, but messy
  • Within a dictionaries.php file where the translated dictionaries are within an array
    • Countries -> countries.{iso2}
    • Currencies -> currencies.{code}

How to reproduce

Create a dictionary fieldtype within come blueprint and change the language to anything !English.

Logs

No response

Environment

Environment
Application Name: Statamic
Laravel Version: 11.28.1
PHP Version: 8.3.12
Composer Version: 2.5.8
Environment: local
Debug Mode: ENABLED
URL: statamic.test
Maintenance Mode: OFF
Timezone: UTC
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: NOT CACHED

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: log
Queue: sync
Session: file

Statamic
Addons: 0
Sites: 1
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 5.31.0 PRO

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

andjsch avatar Oct 17 '24 19:10 andjsch

I'd do something like this:

resources/lang/en/dictionary-countries.php

<?php

return [
    'regions' => [
        'africa' => 'Africa',
        'americas' => 'Americas',
        'asia' => 'Asia',
        'europe' => 'Europe',
        'oceania' => 'Oceania',
        'polar' => 'Polar',
    ],
    'subregions' => [
        'southern_asia' => 'Southern Asia',
        // etc
    ],
    'names' => [
        'AFG' => 'Afghanistan',
        // etc
    ],
];
protected function getItems(): array
    {
        return [
            [
                'name' => __('statamic::dictionary-countries.names.AFG'), 
                'iso3' => 'AFG', 
                'iso2' => 'AF', 
                'region' => __('statamic::dictionary-countries.regions.asia'), 
                'subregion' => __('statamic::dictionary-countries.subregions.southern_asia'),
                'emoji' => '🇦🇫'
            ],
            // etc
        ];

jasonvarga avatar Oct 18 '24 14:10 jasonvarga