techouse / intl-date-time

International DateTime for Laravel Nova
MIT License
57 stars 21 forks source link

Translatable timezones #21

Closed pzmarzly closed 4 years ago

pzmarzly commented 4 years ago

It would be nice to be able to change the way timezones are displayed, by providing translations.

-<span v-if="field.displayUserTimeZone" class="text-80 text-sm ml-2">({{ userTimezone }})</span>
+<span v-if="field.displayUserTimeZone" class="text-80 text-sm ml-2">({{ __(userTimezone) }})</span>

Then we would be able to, for example, present the user with (UK time) instead of (Europe/London), by putting:

"Europe/London": "UK time"

into resources/lang/vendor/nova/en.json.

I'm not sure whether __ is available as Vue helper out of the box, if not, it can be easily implemented like so:

let __ = function (original) {
    let translated = window.config.translations[original];
    if (translated !== undefined) return translated;
    return original;
}
techouse commented 4 years ago

Thanx for the feedback. __ is not available out of the box, however, one can use something like Vue I18n which uses the function call $t('string to translate').

Feel free to make a PR if you'd like. :) Please be sure to test it before submitting it.

techouse commented 4 years ago

Implemented in v1.5.0