deschler / django-modeltranslation

Translates Django models using a registration approach.
BSD 3-Clause "New" or "Revised" License
1.34k stars 257 forks source link

Add a helper to get a list of locales #731

Closed koleror closed 1 month ago

koleror commented 2 months ago

Hey there,

I'd like to add a small helper similar to build_localized_fieldname, but that would only return the lang part. I've been needing this in several parts of my projects, and think had to either use build_localized_fieldname("", lang)[1:] or do it manually, using a simple lang.replace("-", "_"), but in that case I lose the id case handling. I think this need seems quite common, so why not make it a dedicated helper? Something like this (the method name is not great - if you have any better idea):

def build_lang(lang: str) -> str:
    if lang == "id":
        # The 2-letter Indonesian language code is problematic with the
        # current naming scheme as Django foreign keys also add "id" suffix.
        lang = "ind"
    return lang.replace("-", "_") 

I'd be happy to make a PR if you think it could be merged! Just let me know :)

last-partizan commented 2 months ago

Yes, we can merge it!

koleror commented 1 month ago

Sorry, missed your answer. Just made a PR!

koleror commented 1 month ago

Thanks for the merge! Do you have a timeline of when it will be in the next pypi version?

last-partizan commented 1 month ago

Released just now :)