Skip to content

Commit

Permalink
Merge pull request #136 from osmlab/support-address-field-localization
Browse files Browse the repository at this point in the history
Support address field ordering localization
  • Loading branch information
iandees authored Jan 29, 2024
2 parents b03181e + d83ca9c commit c85f115
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 10 deletions.
23 changes: 18 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ <h1 data-i18n="app.title" class="mx-auto text-primary">On OpenStreetMap</h1>
<p data-i18n="step2.addressalt" class="mt-3"></p>
<!-- address 1 -->
<div class="form-row">
<div class="form-group col-md-5">
<!-- Street -->
<div id="streetgroup" class="form-group col-md-5">
<label for='addressalt' data-i18n="step2.street"></label>
<div class="input-group">
<div class="input-group-prepend">
Expand All @@ -123,7 +124,8 @@ <h1 data-i18n="app.title" class="mx-auto text-primary">On OpenStreetMap</h1>
<input id='addressalt' autocomplete="street-address" type='text' placeholder='' class="form-control" data-i18n="[placeholder]step2.addressaltplaceholder" />
</div>
</div>
<div class="form-group col-md-2">
<!-- House number -->
<div id="hnumbergroup" class="form-group col-md-2">
<label for="hnumberalt" data-i18n="step2.housenumber"></label>
<div class="input-group">
<div class="input-group-prepend">
Expand All @@ -132,8 +134,18 @@ <h1 data-i18n="app.title" class="mx-auto text-primary">On OpenStreetMap</h1>
<input type="text" class="form-control" id="hnumberalt" data-i18n="[placeholder]step2.housenumberplaceholder">
</div>
</div>

<div class="form-group col-md-3">
<!-- Place name -->
<div id="placenamegroup" class="form-group col-md-5">
<label for="placenamealt" data-i18n="step2.placename"></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="twa twa-cityscape"></i></span>
</div>
<input type="text" class="form-control" id="placenamealt" data-i18n="[placeholder]step2.placenameplaceholder">
</div>
</div>
<!-- City -->
<div id="citygroup" class="form-group col-md-3">
<label for="city" data-i18n="step2.city"></label>
<div class="input-group">
<div class="input-group-prepend">
Expand All @@ -142,7 +154,8 @@ <h1 data-i18n="app.title" class="mx-auto text-primary">On OpenStreetMap</h1>
<input type="text" class="form-control" id="city" data-i18n="[placeholder]step2.cityplaceholder">
</div>
</div>
<div class="form-group col-md-2">
<!-- Postcode -->
<div id="postcodegroup" class="form-group col-md-2">
<label for="postcode" data-i18n="step2.postcode"></label>
<div class="input-group">
<div class="input-group-prepend">
Expand Down
29 changes: 26 additions & 3 deletions js/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const rerender = () => {
// may have to fix this??
reloadLists(i18next.resolvedLanguage);

// these translations won't get re-copied to their current controls
// these translations won't get re-copied to their current controls
successString = i18n.t('messages.success', {
escapeInterpolation: false
});
Expand All @@ -31,6 +31,29 @@ const rerender = () => {
modalText.text = i18n.t('messages.modalTitle');
modalText.button = i18n.t('messages.modalButton');

// Move the address fields around to match the localization
let parent = $('#hnumbergroup').parent();
let hnumber = $('#hnumbergroup').clone();
let street = $('#streetgroup').clone();
let placename = $('#placenamegroup').clone();
let city = $('#citygroup').clone();
let postcode = $('#postcodegroup').clone();
parent.empty()
if (i18next.resolvedLanguage === 'en-US') {
// US English should show house number before street name and hide place name
parent.append(hnumber);
parent.append(street);
parent.append(city);
parent.append(postcode);
} else {
// All other languages should show street before house number
parent.append(street);
parent.append(placename);
parent.append(hnumber);
parent.append(city);
parent.append(postcode);
}

$('body').localize();
};

Expand Down Expand Up @@ -74,5 +97,5 @@ $(function () {

rerender();
if (err) return console.error(err);
});
});
});
});
1 change: 1 addition & 0 deletions js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ function getNoteBody() {
if ($("#name").val()) note_body += i18n.t('step2.name') + ": " + $("#name").val() + "\n";
if ($("#hnumberalt").val()) note_body += "addr:housenumber=" + $("#hnumberalt").val() + "\n";
if ($("#addressalt").val()) note_body += "addr:street=" + $("#addressalt").val() + "\n";
if ($("#placenamealt").val()) note_body += "addr:place=" + $("#placenamealt").val() + "\n";
if ($("#city").val()) note_body += "addr:city=" + $("#city").val() + "\n";
if ($("#postcode").val()) note_body += "addr:postcode=" + $("#postcode").val() + "\n";
if ($("#phone").val()) note_body += i18n.t('step2.phone') + ": " + $("#phone").val() + "\n";
Expand Down
4 changes: 3 additions & 1 deletion locales/en-GB/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
"cataltdesc": "Description",
"addressalt": "Help us by filling the complete address (housenumber, post code) or improving the previous one",
"street": "Street",
"housenumber": "Housenumber",
"placename": "Place Name",
"housenumber": "House Number",
"city": "City",
"postcode": "Postcode",
"addressaltplaceholder": "West Main Street",
"placenameplaceholder": "Woods Village",
"housenumberplaceholder": "501",
"cityplaceholder": "Alexandria",
"postcodeplaceholder": "50023",
Expand Down
2 changes: 2 additions & 0 deletions locales/en-US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
"cataltdesc": "Description",
"addressalt": "Help us by filling the complete address (housenumber, post code) or improving the previous one",
"street": "Street",
"placename": "Place Name",
"housenumber": "Housenumber",
"city": "City",
"postcode": "Zipcode",
"addressaltplaceholder": "West Main Street",
"placenameplaceholder": "Woods Village",
"housenumberplaceholder": "501",
"cityplaceholder": "Alexandria",
"postcodeplaceholder": "50023",
Expand Down
4 changes: 3 additions & 1 deletion locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
"cataltdesc": "Description",
"addressalt": "Help us by filling the complete address (housenumber, post code) or improving the previous one",
"street": "Street",
"housenumber": "Housenumber",
"placename": "Place Name",
"housenumber": "House Number",
"city": "City",
"postcode": "Postcode",
"addressaltplaceholder": "West Main Street",
"placenameplaceholder": "Woods Village",
"housenumberplaceholder": "501",
"cityplaceholder": "Alexandria",
"postcodeplaceholder": "50023",
Expand Down
2 changes: 2 additions & 0 deletions locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
"cataltdesc": "Descripción",
"addressalt": "Ayúdenos rellenando la dirección completa (número de casa, código postal) o mejorando la anterior",
"street": "Calle",
"placename": "Nombre del lugar",
"housenumber": "Número de casa",
"city": "Ciudad",
"postcode": "Código postal",
"addressaltplaceholder": "Avenida América, España",
"placenameplaceholder": "Pueblo del Bosque",
"housenumberplaceholder": "501",
"cityplaceholder": "Alexandria",
"postcodeplaceholder": "50023",
Expand Down

0 comments on commit c85f115

Please sign in to comment.