Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Country should be a combo field #7123

Open
1ec5 opened this issue Dec 15, 2019 · 8 comments
Open

Country should be a combo field #7123

1ec5 opened this issue Dec 15, 2019 · 8 comments
Labels
field An issue with a field in the user interface new contributor opportunity Best for first-time contributors without prior experience. You won’t be assigned; PRs welcome!

Comments

@1ec5
Copy link
Collaborator

1ec5 commented Dec 15, 2019

The country tag is supposed to be an ISO 3166 alpha-2 code, but not everyone is familiar with the ISO code for their own country (dependent territory, etc.), let alone the country of a consulate or embassy. Meanwhile, tags like country=Turkey and country=United_States_of_America crop up because it looks a lot like a free-form text field.

Mappers would be more likely to enter consistent values if we turn the Country field into a combo field with each choice being a spelled-out country name. As with the multilingual name field (#2457), CLDR would be a natural source for country names localized into every supported language, to avoid additional burden on translators.

Maybe in the future, this work could also come in handy for other tagging schemes that incorporate ISO 3166 codes, like network and cycle_network tags.

@1ec5 1ec5 added the field An issue with a field in the user interface label Dec 15, 2019
@zorae
Copy link

zorae commented Dec 15, 2019

I’ve spent a lot of time cross-referencing ISO 3166 tables when tagging diplomatic offices. This would be a welcome improvement!

@zorae
Copy link

zorae commented Dec 24, 2019

Please note that both country=* and target=* may be a semicolon-delimited list, not just a single country code. See wiki

@1ec5
Copy link
Collaborator Author

1ec5 commented Jul 4, 2020

This MapRoulette challenge includes hundreds of flagpoles to retag where a mapper had written a full country name in the Country field. That could’ve been due to a lack of awareness of the convention to use ISO codes, the inconvenience of looking up an ISO code, or the taginfo-based suggestions that currently show “Tanzania” as the most common value for some reason.

@1ec5
Copy link
Collaborator Author

1ec5 commented Apr 4, 2024

openstreetmap/id-tagging-schema#799 was closed in favor of the CLDR-based approach described above. We already use CLDR for the list of languages in the Multilingual Name field, but at build time, we throw away the rest of the CLDR data, including country names:

let languagesPath = `${cldrMainDir}${code}/languages.json`;

@1ec5
Copy link
Collaborator Author

1ec5 commented Apr 4, 2024

On second thought, we already require browser versions that support Intl.DisplayNames.prototype.of(), so we can just use that method to map each country code to a localized, human-readable string. This would also work for language names, allowing us to remove the dependency on CLDR.

@1ec5 1ec5 added the new contributor opportunity Best for first-time contributors without prior experience. You won’t be assigned; PRs welcome! label Apr 4, 2024
@Abishek-Jayan
Copy link

Hey is this issue being worked on by anyone? From what I see, the change needs to be done in the combo.js file. May I take a crack at it?

@1ec5
Copy link
Collaborator Author

1ec5 commented Jul 10, 2024

No one has posted a pull request for this enhancement yet, so feel free to give it a try.

For what it’s worth, combo.js is deep in the UI code. Most of this field code doesn’t know about the quirks of individual keys or fields. Instead, that’s normally the responsibility of the separate id-tagging-schema repository. Since there are so many potential options to list for this field, we would want to generate them dynamically at runtime instead of hard-coding them in id-tagging-schema, but maybe not directly in the UI code, because other modules like the validator might eventually need the same data.

You might want to look at modules/presets/index.js, where iD loads and processes id-tagging-schema’s data. That would be a more convenient place to add a bunch of options to a particular field, since you wouldn’t have to think about UI at all.

@harshendram
Copy link

harshendram commented Aug 23, 2024

Here's a JavaScript function that takes either a full country name or an ISO code and converts it into the corresponding ISO code. This function uses a predefined mapping of country names to ISO codes:

const countryToISO = {
    "Afghanistan": "AF",
    "Albania": "AL",
    "Algeria": "DZ",
    "United States of America": "US",
    "India": "IN",
    "Turkey": "TR",
    // Add more countries as needed
};

function getISOCode(input) {
    // Convert input to uppercase for case-insensitive comparison
    const upperInput = input.toUpperCase();

    // Check if the input is already an ISO code
    if (Object.values(countryToISO).includes(upperInput)) {
        return upperInput;
    }

    // Find the ISO code for the given country name
    for (const [country, iso] of Object.entries(countryToISO)) {
        if (country.toUpperCase() === upperInput) {
            return iso;
        }
    }

    // If not found, return null or handle the error as needed
    return null;
}

// Example usage
console.log(getISOCode("India")); // Output: IN
console.log(getISOCode("IN"));    // Output: IN
console.log(getISOCode("Turkey")); // Output: TR
console.log(getISOCode("TR"));    // Output: TR

This function works as follows:

  1. It first checks if the input is already an ISO code.
  2. If not, it searches for the corresponding ISO code using the country name.
  3. If the input is neither a valid ISO code nor a recognized country name, it returns null.

we can use i18n-iso-countries library too. I hope my approach is correct ,free for discussions

harshendram added a commit to harshendram/iD that referenced this issue Aug 24, 2024
Country should be a combo field openstreetmap#7123 has been solved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
field An issue with a field in the user interface new contributor opportunity Best for first-time contributors without prior experience. You won’t be assigned; PRs welcome!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants