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.

Greg
  • 18,111
  • 5
  • 46
  • 68
  • 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? – Michael Sep 22 '19 at 06:08
  • the more specific css selectors will win out so if you do all your custom css by ids you should be fine. – kpie Oct 08 '19 at 00:12

1 Answers1

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>