-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
135 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -304,3 +304,10 @@ a { | |
.--capitalized { | ||
text-transform: capitalize; | ||
} | ||
|
||
.--rtl { | ||
direction: rtl; | ||
} | ||
.--ltr { | ||
direction: ltr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Inject } from "@nuxt/types/app"; | ||
import { useLanguageDirection } from "~/v1/infrastructure/services/useLanguageDirection"; | ||
|
||
export default (_, inject: Inject) => { | ||
const language = useLanguageDirection(); | ||
|
||
inject("language", language); | ||
}; |
55 changes: 55 additions & 0 deletions
55
frontend/v1/infrastructure/services/useLanguageDirection.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useLanguageDirection } from "./useLanguageDirection"; | ||
|
||
describe("useLanguageDirection", () => { | ||
const { isRTL } = useLanguageDirection(); | ||
|
||
describe("isRTL should", () => { | ||
test("be true if the text is Arabic", () => { | ||
const text = "مرحبا بالعالم"; | ||
|
||
const result = isRTL(text); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
test("be true if the text is Hebrew", () => { | ||
const text = "שלום עולם"; | ||
|
||
const result = isRTL(text); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
test("be true if the text is Persian", () => { | ||
const text = "سلام دنیا"; | ||
|
||
const result = isRTL(text); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
test("be false if the text is LTR", () => { | ||
const text = "Hello World"; | ||
|
||
const result = isRTL(text); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
|
||
test("be true if the text has more than RTL characters than LTR characters", () => { | ||
const text = "هذا نص مثال Hello"; | ||
|
||
const result = isRTL(text); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
test("be false if the text has more LTR characters than RTL characters", () => { | ||
const text = "Esto es un texto de ejemplo مرحبًا"; | ||
|
||
const result = isRTL(text); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
frontend/v1/infrastructure/services/useLanguageDirection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export const useLanguageDirection = () => { | ||
const isRTL = (text: string) => { | ||
const rtlCount = ( | ||
text.match(/[\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC]/g) || [] | ||
).length; | ||
|
||
const ltrCount = ( | ||
text.match( | ||
// eslint-disable-next-line no-misleading-character-class | ||
/[A-Za-z\u00C0-\u00C0\u00D8-\u00F6\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF\u2C00-\uFB1C\uFDFE-\uFE6F\uFEFD-\uFFFF]/g | ||
) || [] | ||
).length; | ||
|
||
return rtlCount > ltrCount; | ||
}; | ||
|
||
return { | ||
isRTL, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters