From 6ecb3ee705ed738cbe992af3875201682bc0a3bd Mon Sep 17 00:00:00 2001 From: Jason Irish Date: Fri, 6 Sep 2024 12:21:20 -0500 Subject: [PATCH 1/2] FEATURE CMS translations --- 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..cc440da 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', 'Address3'); + $labels['Address2'] = _t(__CLASS__ . '.Address2Label', 'Address 23'); + $labels['City'] = _t(__CLASS__ . '.CityLabel', 'City3'); + $labels['State'] = _t(__CLASS__ . '.StateLabel', 'State/Province3'); + $labels['PostalCode'] = _t(__CLASS__ . '.PostalCodeLabel', 'Postal Code3'); + $labels['Country'] = _t(__CLASS__ . '.CountryLabel', 'Country3'); + $labels['LatLngOverride'] = _t(__CLASS__ . '.LatLngOverrideLabel', 'Override Latitude and Longitude?3'); + $labels['Lat'] = _t(__CLASS__ . '.LatLabel', 'Latitude3'); + $labels['Lng'] = _t(__CLASS__ . '.LngLabel', 'Longitude3'); + } + /** * @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); From 95f54d7f28acea7bf380acf03cde7b2879a3cf31 Mon Sep 17 00:00:00 2001 From: Jason Irish Date: Fri, 6 Sep 2024 12:24:59 -0500 Subject: [PATCH 2/2] cleanup --- src/AddressDataExtension.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/AddressDataExtension.php b/src/AddressDataExtension.php index cc440da..b439444 100644 --- a/src/AddressDataExtension.php +++ b/src/AddressDataExtension.php @@ -53,15 +53,15 @@ class AddressDataExtension extends DataExtension */ public function updateFieldLabels(&$labels) { - $labels['Address'] = _t(__CLASS__ . '.AddressLabel', 'Address3'); - $labels['Address2'] = _t(__CLASS__ . '.Address2Label', 'Address 23'); - $labels['City'] = _t(__CLASS__ . '.CityLabel', 'City3'); - $labels['State'] = _t(__CLASS__ . '.StateLabel', 'State/Province3'); - $labels['PostalCode'] = _t(__CLASS__ . '.PostalCodeLabel', 'Postal Code3'); - $labels['Country'] = _t(__CLASS__ . '.CountryLabel', 'Country3'); - $labels['LatLngOverride'] = _t(__CLASS__ . '.LatLngOverrideLabel', 'Override Latitude and Longitude?3'); - $labels['Lat'] = _t(__CLASS__ . '.LatLabel', 'Latitude3'); - $labels['Lng'] = _t(__CLASS__ . '.LngLabel', 'Longitude3'); + $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'); } /**