4

I've got a project in Vue.js with two styles in arabic and english .. the vuebootstrap style is imported as follow in main.js

import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'

and bootstrap-rtl in head tag inside index.html along side with my custom style.css

the problem here was that the imported files are override my custom css file so I imported as well in main.js

import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
import '../public/css/erx-style-ar.css'

in order to switch between the rtl and ltr css files I was going to select it by id and disable the file using vuei18. as follow

<a role="button" @click="changeLocale('en')" v-if="$i18n.locale=='ar'">En</a>
<a role="button" @click="changeLocale('ar')" v-if="$i18n.locale=='en'">Ar</a>

and in the function

changeStyle(locale) {
            if (locale === 'ar') {
                document.getElementById("style-ar").disabled = false;
                document.getElementById("bootstrap-rtl").disabled = false;
                document.getElementById("style-en").disabled = true;
            }
            if (locale === 'en') {
                document.getElementById("style-ar").disabled = true;
                document.getElementById("bootstrap-rtl").disabled = true;
                document.getElementById("style-en").disabled = false;
            }
        }

now I actually don't know what is the best solution of this situation.

2
  • Have you tried instead of just importing them in main.js have a function which imports based on a parameter (by default you can make it whichever direction you want), then you can call that function which is on main.js to toggle between the styles? Commented Sep 22, 2019 at 6:08
  • the more specific css selectors will win out so if you do all your custom css by ids you should be fine. Commented Oct 8, 2019 at 0:12

1 Answer 1

2

it was solved by sass , put all rtl css inside a main .en class and all ltr css inside .ar class and swith between them by a condition

<div id="app" v-bind:class="[{'ar' : $i18n.locale=='ar' },{'en':$i18n.locale=='en'}]"></div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.