-
Notifications
You must be signed in to change notification settings - Fork 662
Feat/rtl indic script support(#1259) #1326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jayant-1
wants to merge
10
commits into
lingodotdev:main
Choose a base branch
from
Jayant-1:feat/rtl-indic-script-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ffcf8e2
feat: add Nepali (ne) translation of README
Jayant-1 06602dd
feat: add Odia (or) translation of README
Jayant-1 8586bb7
feat: add Marathi (mr) translation of README
Jayant-1 92fd15d
feat: add Sinhala (si) translation of README
Jayant-1 0469180
feat: add RTL and Indic script support
Jayant-1 f428732
Update i18n.json
Jayant-1 c7ee6ee
Update Module-level cache for the parsed config
Jayant-1 4e49d98
Update providing separate components
Jayant-1 d90d5a8
Merge branch 'main' into feat/rtl-indic-script-support
Jayant-1 408f4b1
Merge branch 'main' into feat/rtl-indic-script-support
Jayant-1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,44 @@ | ||
| { | ||
| "languageConfig": { | ||
| "ar": { | ||
| "direction": "rtl", | ||
| "script": "arabic", | ||
| "fontFamily": "'Noto Naskh Arabic', 'Arabic UI', system-ui, -apple-system" | ||
| }, | ||
| "bn": { | ||
| "direction": "ltr", | ||
| "script": "bengali", | ||
| "fontFamily": "'Noto Sans Bengali', 'Bangla Sangam MN', system-ui, -apple-system" | ||
| }, | ||
| "fa": { | ||
| "direction": "rtl", | ||
| "script": "arabic", | ||
| "fontFamily": "'Noto Naskh Arabic', 'Arabic UI', system-ui, -apple-system" | ||
| }, | ||
| "he": { | ||
| "direction": "rtl", | ||
| "script": "hebrew", | ||
| "fontFamily": "'Noto Sans Hebrew', 'Hebrew UI', system-ui, -apple-system" | ||
| }, | ||
| "hi": { | ||
| "direction": "ltr", | ||
| "script": "devanagari", | ||
| "fontFamily": "'Noto Sans Devanagari', 'Devanagari Sangam MN', system-ui, -apple-system" | ||
| }, | ||
| "mr": { | ||
| "direction": "ltr", | ||
| "script": "devanagari", | ||
| "fontFamily": "'Noto Sans Devanagari', 'Devanagari Sangam MN', system-ui, -apple-system" | ||
| }, | ||
| "ne": { | ||
| "direction": "ltr", | ||
| "script": "devanagari", | ||
| "fontFamily": "'Noto Sans Devanagari', 'Devanagari Sangam MN', system-ui, -apple-system" | ||
| }, | ||
| "si": { | ||
| "direction": "ltr", | ||
| "script": "sinhala", | ||
| "fontFamily": "'Noto Sans Sinhala', 'Sinhala Sangam MN', system-ui, -apple-system" | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,39 @@ | ||
| import React from 'react'; | ||
| import { useScriptStyle } from '../hooks/useScriptStyle'; | ||
|
|
||
| interface LocalizedTextProps { | ||
| locale: string; | ||
| children: React.ReactNode; | ||
| className?: string; | ||
| style?: React.CSSProperties; | ||
| as?: keyof JSX.IntrinsicElements; | ||
| } | ||
|
|
||
| export function LocalizedText({ locale, children, className = '', style = {}, as: Component = 'div' }: LocalizedTextProps) { | ||
| const { style: scriptStyle } = useScriptStyle(locale); | ||
|
|
||
| return ( | ||
| <Component className={className} style={{ ...scriptStyle, ...style }}> | ||
| {children} | ||
| </Component> | ||
| ); | ||
| } | ||
|
|
||
| interface LocalizedContentProps { | ||
| locale: string; | ||
| html: string; | ||
| className?: string; | ||
| style?: React.CSSProperties; | ||
| } | ||
|
|
||
| export function LocalizedContent({ locale, html, className = '', style = {} }: LocalizedContentProps) { | ||
| const { style: scriptStyle } = useScriptStyle(locale); | ||
|
|
||
| return ( | ||
| <div | ||
| className={className} | ||
| style={{ ...scriptStyle, ...style }} | ||
| dangerouslySetInnerHTML={{ __html: html }} | ||
| /> | ||
| ); | ||
| } |
This file contains hidden or 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,23 @@ | ||
| import { useMemo } from 'react'; | ||
| import { getScriptConfig, getScriptStyle } from '../utils/scriptConfig'; | ||
|
|
||
| export function useScriptStyle(locale: string) { | ||
| return useMemo(() => { | ||
| const config = getScriptConfig(locale); | ||
| const style = getScriptStyle(locale); | ||
|
|
||
| return { | ||
| config, | ||
| style, | ||
| isRTL: config?.direction === 'rtl', | ||
| hasSpecialScript: Boolean(config?.script && config.script !== 'latin'), | ||
| }; | ||
| }, [locale]); | ||
| } | ||
|
|
||
| export function useScriptDirection(locale: string) { | ||
| return useMemo(() => { | ||
| const config = getScriptConfig(locale); | ||
| return config?.direction || 'ltr'; | ||
| }, [locale]); | ||
| } |
This file contains hidden or 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,60 @@ | ||
| import { readFileSync } from 'fs'; | ||
| import { join } from 'path'; | ||
|
|
||
| interface ScriptConfig { | ||
| direction: 'ltr' | 'rtl'; | ||
| script: string; | ||
| fontFamily: string; | ||
| } | ||
|
|
||
| interface I18nScriptConfig { | ||
| languageConfig: { | ||
| [key: string]: ScriptConfig; | ||
| } | ||
| } | ||
|
|
||
| // Module-level cache for the parsed config | ||
| let cachedConfig: I18nScriptConfig | null | undefined = undefined; | ||
|
|
||
| export function getScriptConfig(locale: string): ScriptConfig | null { | ||
| try { | ||
| if (cachedConfig === undefined) { | ||
| const configPath = join(__dirname, '../config/i18n-scripts.json'); | ||
| cachedConfig = JSON.parse(readFileSync(configPath, 'utf8')) as I18nScriptConfig; | ||
| } | ||
| return cachedConfig?.languageConfig[locale] || null; | ||
| } catch (error) { | ||
| console.error('Error loading script configuration:', error); | ||
| cachedConfig = null; | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| export function getDirectionClass(locale: string): string { | ||
| const config = getScriptConfig(locale); | ||
| return config?.direction || 'ltr'; | ||
| } | ||
|
|
||
| export function getScriptStyle(locale: string): { [key: string]: string } { | ||
| const config = getScriptConfig(locale); | ||
| if (!config) return {}; | ||
|
|
||
| return { | ||
| direction: config.direction, | ||
| fontFamily: config.fontFamily, | ||
| ...(config.direction === 'rtl' && { | ||
| textAlign: 'right', | ||
| }), | ||
| }; | ||
| } | ||
|
|
||
| export function wrapWithScriptStyle(content: string, locale: string): string { | ||
| const config = getScriptConfig(locale); | ||
| if (!config) return content; | ||
|
|
||
| const style = `direction: ${config.direction}; font-family: ${config.fontFamily}; ${ | ||
| config.direction === 'rtl' ? 'text-align: right;' : '' | ||
| }`; | ||
|
|
||
| return `<div style="${style}">${content}</div>`; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.