Skip to content

Commit fad0833

Browse files
authored
Update README.md
1 parent 56ae1b2 commit fad0833

1 file changed

Lines changed: 145 additions & 0 deletions

File tree

README.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# RTL-CSS
2+
3+
![PHP Version](https://img.shields.io/badge/PHP-%3E%3D7.4-blue.svg) ![License](https://img.shields.io/badge/license-MIT-green.svg) ![GitHub issues](https://img.shields.io/github/issues/irmmr/rtl-css.svg) ![GitHub stars](https://img.shields.io/github/stars/irmmr/rtl-css.svg)
4+
5+
RTL-CSS is a PHP module designed to automatically convert CSS styles from left-to-right (LTR) to right-to-left (RTL) direction. This is particularly useful for applications that require localization support for languages that read from right to left, such as Arabic or Hebrew.
6+
7+
RTL-CSS utilizes the [MyIntervals/PHP-CSS-Parser](https://github.com/MyIntervals/PHP-CSS-Parser) library for parsing CSS. This powerful library provides a robust and flexible way to work with CSS stylesheets, allowing us to efficiently analyze and manipulate CSS rules.
8+
## Table of Contents
9+
10+
- [Features](#features)
11+
- [Installation](#installation)
12+
- [Usage](#usage)
13+
- [Examples](#examples)
14+
- [Contributing](#contributing)
15+
- [License](#license)
16+
17+
## Features
18+
19+
- Automatically converts CSS properties to RTL equivalents.
20+
- Supports various CSS properties including `margin`, `padding`, `float`, and more.
21+
- Easy integration with existing PHP projects.
22+
23+
## Installation
24+
25+
To install RTL-CSS, you can clone the repository or include it in your project using Composer. Here are the steps for both methods:
26+
27+
### Clone the Repository
28+
29+
```bash
30+
git clone https://github.com/irmmr/rtl-css.git
31+
```
32+
33+
### Via composer
34+
```bash
35+
composer require irmmr/rtlcss
36+
```
37+
38+
If you're using Composer, you can add RTL-CSS as a dependency in your composer.json file:
39+
```json
40+
{
41+
"require": {
42+
"irmmr/rtl-css": "*"
43+
}
44+
}
45+
```
46+
47+
## Note
48+
I created this project by observing https://github.com/moodlehq/rtlcss-php. One of the reasons was that this project was no longer active and needed some improvements. I tried to add new sections to it and at the same time, I aimed to make it more similar to the original project https://github.com/MohammadYounes/rtlcss/. I don't need to mention that this entire project is modeled and copied from the projects I referred to.
49+
50+
## Usage
51+
52+
To use RTL-CSS in your project, include the main PHP file and call the conversion function. Here’s a simple example:
53+
54+
```php
55+
use Irmmr\RTLCss\Parser as RTLParser;
56+
use Sabberworm\CSS\Parser;
57+
use Sabberworm\CSS\Parsing\SourceException;
58+
59+
// it's very simple and I know this
60+
$css_code = "div { float: left; }";
61+
62+
// parse css code
63+
$css_parser = new Parser($css_content);
64+
65+
try {
66+
$css_tree = $css_parser->parse();
67+
} catch (SourceException $e) {
68+
// Error occ
69+
return;
70+
}
71+
72+
// create rtlcss parser
73+
$rtlcss = new RTLParser($css_tree);
74+
75+
// parsing css rules and properties
76+
$rtlcss->flip();
77+
78+
// get parsed css code ==> div {float: right;}
79+
echo $css_tree->render();
80+
```
81+
82+
## Directives
83+
Directives are a set of instructions that you can use to create certain commands for the generated RTL code. For example, you can change or remove some selectors, or make it so that rtlcss does not modify them.
84+
85+
- `ignore`
86+
- `remove`
87+
- `raw`
88+
- `rename`
89+
- `discard`
90+
91+
#### Ignore
92+
```css
93+
/* rtl:ignore */
94+
div {
95+
float: right;
96+
text-align: right;
97+
font-size: 15px;
98+
}
99+
100+
/* rtl:ignore:margin-left */
101+
a {
102+
margin-left: 10px;
103+
background-position: 10px;
104+
}
105+
```
106+
```css
107+
div {
108+
float: right;
109+
text-align: right;
110+
font-size: 15px;
111+
}
112+
113+
a {
114+
margin-left: 10px;
115+
background-position: right 10px top 50%;
116+
}
117+
```
118+
119+
120+
## Examples
121+
122+
```css
123+
.example {
124+
display: inline-block;
125+
padding: 5px 10px 15px 20px;
126+
margin: 5px 10px 15px 20px;
127+
border-style: dotted dashed double solid;
128+
border-width: 1px 2px 3px 4px;
129+
border-color: red green blue black;
130+
box-shadow: -1em 0 0.4em gray, 3px 3px 30px black;
131+
}
132+
```
133+
Output:
134+
```css
135+
.example {
136+
display: inline-block;
137+
padding: 5px 20px 15px 10px;
138+
margin: 5px 20px 15px 10px;
139+
border-style: dotted solid double dashed;
140+
border-width: 1px 4px 3px 2px;
141+
border-color: red black blue green;
142+
box-shadow: 1em 0 0.4em gray, -3px 3px 30px black;
143+
}
144+
```
145+

0 commit comments

Comments
 (0)