Transliteration in topic URL

Here!

Some Vietnamese words with diacritics like: ă; â; ơ; ô; ả; ã convert poorly:

Cần thuê mặt bằng 2 MT mở quán cà phê có thể ở lại giá 10tr trở về

It converts to:

c-n-thue-m-t-b-ng-2-mt-m-quan-ca-phe-co-th-l-i-gia-10tr-tr-v/

I want it to convert to:

can thue mat bang 2 mt mo quan ca phe co the o lai gia 10tr tro ve

On WordPress, Vietnamese topic titles convert beautifully, removing only the diacritics from the full text.

3 лайка

@gerhard any ideas?

Looks like it’s working fine when we explicitely set the locale

(Note: parameterize internally calls transliterate)

> I18n.transliterate("Cần")
=> "C?n"
> I18n.transliterate("Cần", locale: "vi")
=> "Can"

We should probably set I18n.locale to the value of SiteSetting.default_locale?

1 лайк

Your default locale is set to English and the system doesn’t know how to correctly transliterate Vietnamese characters in that case. Either change the default locale site setting to Vietnamese or change the slug generation method site setting to “encoded”.

That’s exactly what’s happening in the app, but you have to do it manually in the rails console. :wink:
So, I guess the only thing we should do here is to put a I18n.with_locale(SiteSetting.default_locale) in Slug.ascii_generator, because currently it will use the user’s locale when allow user locale is enabled. Which is kinda weird.

6 лайков

Can you add that to your list?

1 лайк

Fixed in FIX: Generate ASCII slug with default locale · discourse/discourse@56f6065 · GitHub

4 лайка