Localisation of country names - sql

As part of addresses I am storing in my SQL database country codes (e.g. US, DE,...). I then have another table (with two columns) in my database which translates the country codes to the English language names of the respective countries.
If I want to make the site multi-language, I could expand this translation table adding country names in other languages than English.
I was wondering if there is another method which does not involve modification of the database, e.g. using gettext to translate the English country names?

The typical way to handle this is to change the table structure to have three columns, instead of two:
Language
CounryCode
FullName
Whenever you query the database, you would provide the current language.
You then have to change your code to include the additional language key in any queries.
Depending on how you are going to keep track of the current language, you would also use a view or user defined function.
You don't want to use automated translation, since the name of a country like "China" could turn into the equivalent of "porcelain".

Related

What is the industry standard way to store country / state / city in a database of web APP?

For country and state, there are ISO numbers. With City, there is not.
Method 1:
Store in one column:
[Country ISO]-[State ISO]-[City Name]
Method 2:
Store in 3 separate columns.
Also, how to handle city names if there is no unique identifier?
First and foremost, three separate columns to keep your data. If you want to create a unique identifier, the easiest way would be giving a random 3-10 digit code depending on the size of your data set. However, I would suggest concatenating [country-code]-[state-code]-[code] if you have a small data set and if you want human readability to a certain point. code can be several things. Here are some ideas:
of course a random id or even a database row id
licence plate number/code if there is for a city
phone area code of the city or the code of the center
same logic may apply to zip codes
combination of latitude and longitude of the city center up to certain degree
Here are also more references that can be used:
ISO 3166 is a country codes. In there you can find codes for states or cities depending on the country.
As mentioned IATA has both Airport and City codes list but they are hard to obtain.
UN Location list is a good mention but it can be difficult to gather the levels of differentiation, like the airport code or city code or a borough code can be on the same list, but eventually the UN/LOCODE must be unique. (Airport codes are used for ICAO, similar to IATA but not the same)
there are several data sets out there like OpenTravelData or GeoNames that can be used for start but may require digging and converting. They provide unique codes for locations. And many others can be found.
Bonus:
I would suggest checking Schema.org's City Schema and other Place Schemas for a conscious setup.

how to add dyanmic parent child relationship in jira custom field?

I am trying to migrate some of my bugzilla data to JEERA. I have some custom fields in bugzilla which has dynamic parent-child relationship. for exa-
Suppose I have Labels "India" "China" "Russia",
when I click on Label lets say "India", then it should fetch and show only cities from India and not all cities.
Right now , I am able to create Labels and cities custome fields in jeera but lacking dynamic nature.
I will be thankful, if anyone has any idea over this.
Perhaps Select List (cascading) custom field type would best solution here.
As a bit workaround for relate two custom fields between each other you can use ScriptRunner Behaviours. It's like a Groovy definition for frontend logic. Conceptually:
City field must contains all Cities for all Countries.
Create a Behaviour for a Country field. It means when user will change/select a Country field a Behaviour will be run.
In behaviour write code that will get currently selected country and then fulfil a Cities field based on selected country.
Useful methods: getFieldById(fieldId), formField.getValue(), formField.setFieldOptions(Iterable). API Documentation.
I think #sintasy is right.
If you want N-countries have their own cities, cascading select list just fit your requrement.
If you want N-countries * M-other-things, which have no relation with countries, two select lists will fit your requrement.
If you want more complex feature, then I don't known.

How to force a City entity to have its name available in all locales (languages)?

I would like to design a database where the city name MUST exist in all the available locales (languages). I currently serve these locales:
en, fr, it and es.
My initial thought is to save the name inside the cities table but instead of having one name field, I'd have name-en, name-fr, name-es and name-it.
Thus, the city of London would be saved like this inside the cities table:
My second thought is that it'd be more production-appropriate to have a table of all served locales so that once we add a new locale it'd appear on the website automatically as an extra option. Thus, I made this ERD:
Which means that the many-to-many between City and Locale would generate the following table:
So far so good, but I'm not sure how to FORCE that once a new city is added it MUST has it's name available in all locales. Or is that only possible using backend code?
Note:
This is a hiring assignment, so I don't have specific business rules just to think of a smart and scalable solution.
Thanks.
In your first solution, you can use a check constraint:
alter table t add constraint check_all_names
check (name_en is not null and name_fr is not null and name_es is not null and name_it is not null);
The second is basically not possible with a well-designed data model in SQL. Why?
To insert into city_locales you need a valid city_id.
By definition, you cannot have a valid city_id until you have all locales.
Further, constraints generally need to be true as rows are inserted. You cannot insert one row into city_locales and have the constraint be true (assuming you have more than one locale).
One way around this would be to have a flag on the cities table that specifies if all locales are created. You can update the number of locales using a trigger. Or, you can use a view and calculate the flag on the fly.

how to fix spelling mistakes in a database have multiple records in that records there are more records

i have a database having country, city, state and hotels in these table country name has multiple identical records for eg mexico is wrongly spelled as maxico and mxico and mexico,other records like usa and united states of america and america these type of records are having mutiple same wrongly spelled states and states has multiple wrong spelled cities but hotels are unique and i want them to set them to there right city and state and country for eg. some hotel is in chicago city Illinois state and country is usa. please help me how can i fix this
you could do an update if you know all the different scenarios that are incorrect
update tbl
set city = 'Mexico'
where city in ('maxico', 'mxico')
Well,you can list all values the country column has,and then check wether the values is right, if it is wrong, just use update clause to fix the wrong value, like below:
update my_table set country = 'Mexico' where country in ('maco', 'xico');
It depends on infrastructure you're running.
If you have access to some ETL tools, they often have DataQuality capabilities, often with databases used in correcting adresses. Those are often paid.
If you are a "private" developer, then you might not want to use paid data, so you can look for open data sources, like https://catalog.data.gov allegheny country addresses.
You can use multitude of algorithms and solutions, ranging from simple distances in word space to neural networks pre-trained to do just that.
This type of data problem is hard. There is no built-in simple way to determine the "right spelling". Many databases have one of two capabilities built in that can help -- either "soundex" algorithms or Levenshtein distance.
What should you do? If you really want to fix this problem, create a table with the misspelled name and the correct value that you want. This table will need to be maintained manually, such as in a spreadsheet. Then use this table when importing data and use only the rectified value.
Better yet, set up a reference table with only the correct names. Create a second table with alternative names, which is maintained as above.

Relational Entity with one Model Class

I am facing Problem with Entity Framework with MVC 4 .
Let me put the Table Structure and result which i needed.
as you can see i have three table and the data structure is
can anyone suggest me how can i write Model class so that on create country page i have layout like
select Language -- Language Dropdownlist Box here
Enter Country name- country text Box here
Thanks
Ashutosh
As already said, you have problems with your table structure, and a model will reflect this, not correct it. And while I am at it, German and Chinese are languages, while Germany and China are countries.
Country Names should be in Countries table, while country_languages is a table allowing a many to many relationship and as such should never be seen by your end user.
If you define your model properly with only Countries and Languages, Entity Framework with Code First will generate a correct Countries_Languages table for you.
Don't forget that in some countries, more than one language is spoken, like Switzerland which has 4 official languages....