Skip to content

Commit

Permalink
FEATURE CMS translations (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirish authored Sep 6, 2024
1 parent 243a244 commit b84f6ac
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
Empty file added lang/_manifest_exclude
Empty file.
12 changes: 12 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
@@ -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'
50 changes: 38 additions & 12 deletions src/AddressDataExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* Class \Dynamic\SilverStripeGeocoder\AddressDataExtension
*
* @property CompanyAddress|AddressDataExtension $owner
* @property AddressDataExtension $owner
* @property string $Address
* @property string $Address2
* @property string $City
Expand Down Expand Up @@ -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
*/
Expand All @@ -66,30 +82,40 @@ 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;
$googleMapDiv = '<div class="field"><label class="left" for="Form_EditForm_MapURL_Readonly">Google Map</label><div class="middleColumn"><a href="' . $googleMapURL . '" target="_blank">' . $googleMapURL . '</a></div></div>';
$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);
Expand Down

0 comments on commit b84f6ac

Please sign in to comment.