How Do You Source Common Elements Like Countries, Languages, and Currencies for Your Project?
Asked by
!pay at the counter
I'm deep into a project right now and I've been saving currencies and languages as simple IDs (like 'en' for English, 'de' for German) in my database. But I'm realizing that showing these in the UI is a whole different ball gameโmost users won't know that 'de' means Germany! I've looked into some APIs, but I'm not sure which ones are reliable. I'm considering creating my own API or container, but I thought I'd reach out to see what you all do for these common elements. Any tips or resources?
Answers
You can take advantage of various frameworks like Vue, React, or Angular. For each language, maintain a JSON file with tokens (like 'en' for English, 'de' for German) that correspond to the text you want to display. Additionally, the Intl interface in JavaScript is super helpful for localizing text, including country names, currencies, and dates.
Reply to this answer
If you're up for a bit of coding, you could write a JavaScript snippet to scrape country codes and names from Wikipedia and convert that into a CSV or JSON. Be careful with relying on AI like ChatGPT for names, though; it's likely to have inaccuracies that could trip you up later. You could also use simple scripts to scrape multiple pages for a comprehensive database of countries, currencies, and languages.
Reply to this answer
Don't forget that a simple Google search can point you towards a lot of useful resources!
Reply to this answer
If you're sticking to ISO standards, there are tons of libraries and APIs available that can translate those IDs into user-friendly names and flags. For instance, I use flagcdn.com for iconsโgreat for displaying country flags alongside their codes!
Reply to this answer
You're on the right track by using IDs internally! Just make sure to display readable names or icons in the UI. Users won't associate 'de' with Germany unless you give them extra context.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions