# Why is RTL class user dependent instead of locale?

**URL:** <https://meta.discourse.org/t/why-is-rtl-class-user-dependent-instead-of-locale/54077>\
**Category:** Development\
**Created:** [Dezembro 11, 2016, 3:04am UTC](https://meta.discourse.org/t/why-is-rtl-class-user-dependent-instead-of-locale/54077 "2016-12-11T03:04:10Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![ibnesayeed](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ibnesayeed/32/120427_2.png) [@ibnesayeed](https://meta.discourse.org/u/ibnesayeed)\
**Post date:** [Dezembro 11, 2016, 3:04am UTC](https://meta.discourse.org/t/why-is-rtl-class-user-dependent-instead-of-locale/54077/1 "2016-12-11T03:04:10Z")

</div>

Recently, I [added support for Urdu language](https://meta.discourse.org/t/urdu-language-support-added/53877), which, like Arabic, Hebrew, and Persian, is an RTL (right-to-left) language. To make the software aware of it I added `ur` locale in `rtl_locales` method of the `RTL` model class.

> <https://github.com/discourse/discourse/blob/49fc54aac603fee08a6fb1e8b9610a0537ca9ec2/app/models/rtl.rb#L21-L23>

However, my site’s direction did not change in right-to-left. So, I started investigating what’s wrong? I found that there is a helper method `rtl?` in the `ApplicationHelper` class.

> <https://github.com/discourse/discourse/blob/49fc54aac603fee08a6fb1e8b9610a0537ca9ec2/app/helpers/application_helper.rb#L137-L139>

There seems some duplication of logic. So, I looked into the `RTL` class further and found it confusing because it’s initialization is dependent on a `User` instance.

> <https://github.com/discourse/discourse/blob/49fc54aac603fee08a6fb1e8b9610a0537ca9ec2/app/models/rtl.rb#L1-L7>

This implementation would make perfect sense if RTL is a property independent of the locale in a way that my Arabic may be RTL, but your Arabic may not. However, this is not the case. RTL (or LTR) is the property of the locale, independent of the user. If the `I18n.locale` is assigned a property called `direction` which may hold values `rtl` or `ltr`, with `ltr` being the default (let’s forget about the `ttb` direction for now because that is almost always represented as `ltr` on the web). Alternatively, a method `rtl?` is added to the `I18n.locale` that returns false by default, unless the locale is in the array of RTL locales.

This way, entire RTL class can go away and wherever a locale object is accessible, its direction is also known. We don’t need to know separately if a user’s locale has RTL enabled, we just find the effective locale and apply RTL if applicable.

I know that Discourse does not encourage code refactoring for the sake of refactoring, but being a newbie to the code base I would like to hear the rationale behind why it is the way it is?

---

_[View the full topic](https://meta.discourse.org/t/why-is-rtl-class-user-dependent-instead-of-locale/54077)._
