From b84f6acb01580c365203531ea7d19c941b9002ea Mon Sep 17 00:00:00 2001 From: Jason Irish Date: Fri, 6 Sep 2024 12:30:52 -0500 Subject: [PATCH] FEATURE CMS translations (#72) --- lang/_manifest_exclude | 0 lang/en.yml | 12 +++++++++ src/AddressDataExtension.php | 50 +++++++++++++++++++++++++++--------- 3 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 lang/_manifest_exclude create mode 100644 lang/en.yml diff --git a/lang/_manifest_exclude b/lang/_manifest_exclude new file mode 100644 index 0000000..e69de29 diff --git a/lang/en.yml b/lang/en.yml new file mode 100644 index 0000000..5d028ab --- /dev/null +++ b/lang/en.yml @@ -0,0 +1,12 @@ +en: + Dynamic\SilverStripeGeocoder\AddressDataExtension: + AddressLabel: 'Address' + Address2Label: 'Address 2' + CityLabel: 'City' + StateLabel: 'State/Province' + PostalCodeLabel: 'Postal Code' + CountryLabel: 'Country' + LatLngOverrideLabel: 'Override Latitude and Longitude' + LatLngOverrideDescription: 'Check this box and save to be able to edit the latitude and longitude manually.' + LatLabel: 'Latitude' + LngLabel: 'Longitude' diff --git a/src/AddressDataExtension.php b/src/AddressDataExtension.php index a9cf668..b439444 100644 --- a/src/AddressDataExtension.php +++ b/src/AddressDataExtension.php @@ -20,7 +20,7 @@ /** * Class \Dynamic\SilverStripeGeocoder\AddressDataExtension * - * @property CompanyAddress|AddressDataExtension $owner + * @property AddressDataExtension $owner * @property string $Address * @property string $Address2 * @property string $City @@ -48,6 +48,22 @@ class AddressDataExtension extends DataExtension 'Lng' => 'Decimal(10,7)', ]; + /** + * @var array + */ + public function updateFieldLabels(&$labels) + { + $labels['Address'] = _t(__CLASS__ . '.AddressLabel', 'Address'); + $labels['Address2'] = _t(__CLASS__ . '.Address2Label', 'Address 2'); + $labels['City'] = _t(__CLASS__ . '.CityLabel', 'City'); + $labels['State'] = _t(__CLASS__ . '.StateLabel', 'State/Province'); + $labels['PostalCode'] = _t(__CLASS__ . '.PostalCodeLabel', 'Postal Code'); + $labels['Country'] = _t(__CLASS__ . '.CountryLabel', 'Country'); + $labels['LatLngOverride'] = _t(__CLASS__ . '.LatLngOverrideLabel', 'Override Latitude and Longitude?'); + $labels['Lat'] = _t(__CLASS__ . '.LatLabel', 'Latitude'); + $labels['Lng'] = _t(__CLASS__ . '.LngLabel', 'Longitude'); + } + /** * @param FieldList $fields */ @@ -66,18 +82,28 @@ public function updateCMSFields(FieldList $fields) ]); $fields->addFieldsToTab('Root.' . $tab_name, [ - TextField::create('Address'), - TextField::create('Address2', 'Address 2'), - TextField::create('City'), - TextField::create('State', 'State/Province'), - TextField::create('PostalCode'), + TextField::create('Address') + ->setTitle($this->owner->fieldLabel('Address')), + TextField::create('Address2', 'Address 2') + ->setTitle($this->owner->fieldLabel('Address2')), + TextField::create('City') + ->setTitle($this->owner->fieldLabel('City')), + TextField::create('State', 'State/Province') + ->setTitle($this->owner->fieldLabel('State')), + TextField::create('PostalCode') + ->setTitle($this->owner->fieldLabel('PostalCode')), CountryDropdownField::create('Country') + ->setTitle($this->owner->fieldLabel('Country')) ->setEmptyString('Select Country'), ]); $compositeField = CompositeField::create(); - $compositeField->push($overrideField = CheckboxField::create('LatLngOverride', 'Override Latitude and Longitude?')); - $overrideField->setDescription('Check this box and save to be able to edit the latitude and longitude manually.'); + $compositeField->push($overrideField = CheckboxField::create('LatLngOverride', 'Override Latitude and Longitude?') + ->setTitle($this->owner->fieldLabel('LatLngOverride'))); + $overrideField->setDescription(_t( + __CLASS__ . '.LatLngOverrideDescription', + 'Check this box and save to be able to edit the latitude and longitude manually3.' + )); if ($this->owner->Lng && $this->owner->Lat) { $googleMapURL = 'https://maps.google.com/?q=' . $this->owner->Lat . ',' . $this->owner->Lng; @@ -85,11 +111,11 @@ public function updateCMSFields(FieldList $fields) $compositeField->push(LiteralField::create('MapURL_Readonly', $googleMapDiv)); } if ($this->owner->LatLngOverride) { - $compositeField->push(TextField::create('Lat', 'Lat')); - $compositeField->push(TextField::create('Lng', 'Lng')); + $compositeField->push(TextField::create('Lat', 'Lat')->setTitle($this->owner->fieldLabel('Lat'))); + $compositeField->push(TextField::create('Lng', 'Lng')->setTitle($this->owner->fieldLabel('Lng'))); } else { - $compositeField->push(ReadonlyField::create('Lat_Readonly', 'Lat', $this->owner->Lat)); - $compositeField->push(ReadonlyField::create('Lng_Readonly', 'Lng', $this->owner->Lng)); + $compositeField->push(ReadonlyField::create('Lat_Readonly', 'Lat', $this->owner->Lat)->setTitle($this->owner->fieldLabel('Lat'))); + $compositeField->push(ReadonlyField::create('Lng_Readonly', 'Lng', $this->owner->Lng)->setTitle($this->owner->fieldLabel('Lng'))); } $fields->addFieldToTab('Root.' . $tab_name, $compositeField);