Question

I'm trying to create an app that would store some data in Serbian language (which is written in both Cyrillic and Latin script), and depending on users choice it would be able to display it in chosen script. Conversion from Cyrillic to Latin is pretty straight forward, because every Cyrillic character has its analogue (or two of them) in Latin ('Б'->'B','Ш'->'Š','Љ'->'LJ'...), but the other way around can get a bit complicated ('LJ'->'Љ' or 'LJ'->'ЛЈ', there's no way to tell a program how to decide, even though most of the time 'LJ'->'Љ' would be correct choice). Anyway, I'm going for Cyrillic input, but I need both Latin and Cyrillic output. So, my question is: What would be the most efficient way to accomplish this? Should I do string conversion in forms.py and store data in different tables (that doesn't sound efficient) or is it better to do the conversion in views? Some JavaScript in templates would be another option I guess, but I believe that this isn't a very good idea. I'm pretty new to Django, so please forgive if I'm asking nonsense.

Was it helpful?

Solution

I think it's easiest to handle Serbian Cyrillic (official) and Serbian Latin as two different 'languages'. Than you get all the benefits of the Django framework and its internationalization and localization machinery.

locale name: sr and sr_Latn.

UPDATE

Above takes care of strings in models, views, forms and templates. But you need to translate the database values.

If you can automate your translation (no or little exceptions) you can use a custom template filter. But if you want your editors to be able to correct not foreseen exceptions, than you have to create database fields to store the translation. Like you would in any multiple language project. There are many model structures and apps to do this. It all depends on your project needs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top