feat: Select css-rtl folder if language is rtl

This commit is contained in:
Suraj Shetty 2021-06-28 12:03:00 +05:30
parent 7e6b00fd3c
commit 30f9207091
2 changed files with 14 additions and 8 deletions

View file

@ -168,9 +168,13 @@ frappe.assets = {
}
},
bundled_asset(path) {
bundled_asset(path, is_rtl=null) {
if (!path.startsWith('/assets') && path.includes('.bundle.')) {
return frappe.boot.assets_json[path] || path;
path = frappe.boot.assets_json[path] || path;
if (path.endsWith('.css') && is_rtl) {
path = path.replace('/css/', '/css-rtl/');
}
return path;
}
return path;
}

View file

@ -75,24 +75,26 @@ def include_script(path):
def include_style(path, rtl=None):
path = bundled_asset(path)
if rtl is None:
rtl = is_rtl()
if rtl:
if is_rtl(rtl):
path = path.replace('/css/', '/css-rtl/')
return f'<link type="text/css" rel="stylesheet" href="{path}">'
def bundled_asset(path):
def bundled_asset(path, rtl=None):
from frappe.utils import get_assets_json
from frappe.website.utils import abs_url
if ".bundle." in path and not path.startswith("/assets"):
bundled_assets = get_assets_json()
path = bundled_assets.get(path) or path
if path.endswith('.css') and is_rtl(rtl):
path = path.replace('/css/', '/css-rtl/')
return abs_url(path)
def is_rtl():
def is_rtl(rtl=None):
from frappe import local
return local.lang in ["ar", "he", "fa", "ps"]
if rtl is None:
return local.lang in ["ar", "he", "fa", "ps"]
return rtl