statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
4.03k stars 530 forks source link

Translate default dictionaries #10972

Closed andjsch closed 1 week ago

andjsch commented 2 weeks ago

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.

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

jasonvarga commented 2 weeks ago

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
        ];