Skip to content
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

Fix Arabic Selection Option #1236

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
1bea99d
Fix Arabic Language
Dec 28, 2024
d30ef26
Fix Arabic
BasselArt Dec 29, 2024
eb054d8
Change the default font
BasselArt Dec 29, 2024
0c3c071
Enhance Arabic Translation
BasselArt Dec 29, 2024
33508d4
Enhance Arabic Translation
BasselArt Dec 29, 2024
42c33e2
Fix Images Gravater
BasselArt Dec 29, 2024
697b117
Remove Unicode
BasselArt Dec 29, 2024
f3a0a52
Add Arabic Support to Avatar Generator
BasselArt Dec 29, 2024
24479c8
Add Arabic Support to Avatar Generator
BasselArt Dec 29, 2024
8e96e60
Add Arabic Support to Avatar Generator
BasselArt Dec 29, 2024
f4c2956
Fix Images Generator
BasselArt Dec 29, 2024
975e8ad
Update docker-compose.yml
BasselArt Dec 29, 2024
6665089
Add docker-compose.yml to .gitignore
BasselArt Dec 29, 2024
2a5e38e
Stop tracking docker-compose.yml
BasselArt Dec 29, 2024
422a341
Fix Letters Generator
BasselArt Dec 29, 2024
ed4a307
Fix Letters Generator
BasselArt Dec 29, 2024
cf08f49
fix: add Arabic font support and SVG upload
BasselArt Dec 29, 2024
fa515e1
fix: add Arabic font support and SVG upload
BasselArt Dec 29, 2024
b265097
fix: add Arabic font support and SVG upload
BasselArt Dec 29, 2024
2c1226f
fix: add Arabic font support and SVG upload
BasselArt Dec 29, 2024
31108ef
fix: add Arabic font support and SVG upload
BasselArt Dec 29, 2024
c811aed
fix: add Arabic font support and SVG upload
BasselArt Dec 29, 2024
a0f2f2e
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
8756c8c
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
33810e2
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
4d97357
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
47a2b93
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
dadb561
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
02e3b55
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
73ab727
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
8d23d0d
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
d65f76f
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
c92f7b1
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
eb21600
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
03774f5
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
c628caf
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
8e32a86
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
2defc58
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
319ab80
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
b87e902
fix: add Arabic font support and SVG upload
BasselArt Dec 30, 2024
d762c41
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
d7cf868
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
b033467
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
850e562
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
6473523
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
e65a179
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
1653f56
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
22a2903
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
a99fcbf
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
300c424
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
6e37e27
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
fc0cdaf
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
951b64a
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
f04f073
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
0eb592a
fix: add Arabic font support and SVG upload
BasselArt Dec 31, 2024
6220200
fix: Enhance Arabic Compatibility
BasselArt Dec 31, 2024
9e68a53
fix: Enhance Arabic Compatibility
BasselArt Dec 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/handlers/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
"github.com/getfider/fider/app/pkg/bus"
"github.com/getfider/fider/app/pkg/crypto"
"github.com/getfider/fider/app/pkg/env"
"github.com/getfider/fider/app/pkg/letteravatar"
"github.com/getfider/fider/app/pkg/log"
"github.com/getfider/fider/app/pkg/web"
"github.com/goenning/imagic"
"github.com/goenning/letteravatar"
)

// LetterAvatar returns a letter gravatar picture based on given name
Expand All @@ -38,7 +38,7 @@ func LetterAvatar() web.HandlerFunc {
}
size = between(size, 50, 200)

img, err := letteravatar.Draw(size, strings.ToUpper(letteravatar.Extract(name)), &letteravatar.Options{
img, err := letteravatar.Draw(size, letteravatar.Extract(name), &letteravatar.Options{
PaletteKey: fmt.Sprintf("%s:%s", id, name),
})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions app/pkg/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var localeToPlurals = map[string]string{
"it": "it",
"tr": "tr",
"zh-CN": "zh",
"ar": "ar",
}

type Params map[string]any
Expand Down
1,794 changes: 1,794 additions & 0 deletions app/pkg/letteravatar/fonts/IBMPlexSansArabic-Regular.ttf

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions app/pkg/letteravatar/letteravatar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package letteravatar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks interesting. So you use the font to generate the letter avatar, so that it supports arabic letters. That's cool - if we used this we'd just need to make sure we can support both arabic and non-arabic. Do you have any thoughts about how best to manage that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I give up and convert the Arabic letters to English,Ex: ب = B , from my very basic experience with php and converting text to image, Arabic language is very challenging


import (
"embed"
"image"
"image/color"
"image/draw"
"math"
"strings"
"unicode"

"github.com/golang/freetype"
"github.com/golang/freetype/truetype"
"golang.org/x/image/font"
)

//go:embed fonts
var fonts embed.FS

// Options contains the options for letter avatar generation
type Options struct {
PaletteKey string
}

// Extract returns the first letter of each word in the given name
func Extract(name string) string {
if name == "" {
return "?"
}

words := strings.Fields(name)
if len(words) == 0 {
return "?"
}

firstWord := []rune(words[0])
if len(firstWord) == 0 {
return "?"
}

firstLetter := string(firstWord[0])
return firstLetter
}

// Draw generates a letter avatar image with the given size and text
func Draw(size int, text string, opts *Options) (image.Image, error) {
// Create a new RGBA image
img := image.NewRGBA(image.Rect(0, 0, size, size))

// Generate a background color based on the text
bg := generateColor(text, opts.PaletteKey)

// Draw the background
draw.Draw(img, img.Bounds(), &image.Uniform{bg}, image.Point{}, draw.Src)

// Load the font
fontBytes, err := fonts.ReadFile("fonts/IBMPlexSansArabic-Regular.ttf")
if err != nil {
return nil, err
}

f, err := truetype.Parse(fontBytes)
if err != nil {
return nil, err
}

// Calculate font size (40% of image size)
fontSize := float64(size) * 0.4

// Create a new context for drawing text
c := freetype.NewContext()
c.SetDPI(72)
c.SetFont(f)
c.SetFontSize(fontSize)
c.SetClip(img.Bounds())
c.SetDst(img)
c.SetSrc(image.White)
c.SetHinting(font.HintingFull)

// Get text bounds
bounds, err := c.DrawString(text, freetype.Pt(0, 0))
if err != nil {
return nil, err
}

// Calculate text position to center it
textWidth := int(bounds.X.Round())
textHeight := int(c.PointToFixed(fontSize).Round())
x := (size - textWidth) / 2
y := (size + textHeight) / 2

// Draw the text
_, err = c.DrawString(text, freetype.Pt(x, y))
if err != nil {
return nil, err
}

return img, nil
}

// generateColor generates a color based on the text
func generateColor(text, key string) color.Color {
// Simple hash function
hash := 0
for _, r := range text + key {
hash = int(r) + ((hash << 5) - hash)
}

// Convert hash to color
hue := float64(hash%360) / 360.0
saturation := 0.5
value := 0.95

// Convert HSV to RGB
h := hue * 6.0
c := value * saturation
x := c * (1.0 - math.Abs(math.Mod(h, 2.0)-1.0))
m := value - c

var r, g, b float64
switch int(h) {
case 0:
r, g, b = c, x, 0
case 1:
r, g, b = x, c, 0
case 2:
r, g, b = 0, c, x
case 3:
r, g, b = 0, x, c
case 4:
r, g, b = x, 0, c
default:
r, g, b = c, 0, x
}

return color.RGBA{
R: uint8((r + m) * 255),
G: uint8((g + m) * 255),
B: uint8((b + m) * 255),
A: 255,
}
}
19 changes: 15 additions & 4 deletions locale/ar/client.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"action.change": "تغيير",
"action.close": "إغلاق",
"action.confirm": "تأكيد",
"action.copylink": "نسخ الرابط",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, we don't manage changes to the localised strings here.

Please can you make the changes to the arabic strings here: https://crowdin.com/project/fider

Then they can be pulled into the next release

Thanks

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure I will upload an updated version, but I still have some modification on it along with some missing strings

"action.delete": "حذف",
"action.edit": "تحرير",
"action.markallasread": "تحديد الكل كمقروء",
Expand All @@ -11,20 +12,21 @@
"action.save": "حفظ",
"action.signin": "تسجيل الدخول",
"action.submit": "إرسال",
"email.new_comment.text": "علق على",
"enum.poststatus.completed": "مكتمل",
"enum.poststatus.declined": "مرفوض",
"enum.poststatus.deleted": "محذوف",
"enum.poststatus.duplicate": "مكرر",
"enum.poststatus.open": "مفتوح",
"enum.poststatus.planned": "مخطط له",
"enum.poststatus.started": "بدأ",
"enum.poststatus.started": "بدأ العمل عليه",
"error.expired.text": "الرابط الذي نقرت عليه قد انتهت صلاحيته.",
"error.expired.title": "منتهي الصلاحية",
"error.forbidden.text": "أنت غير مخول لعرض هذه الصفحة.",
"error.forbidden.title": "ممنوع",
"error.internalerror.text": "حدث خطأ ونحن نعمل على إصلاح المشكلة! سنكون في الخدمة قريباً.",
"error.internalerror.title": "عفواً! هذا غير متوقع...",
"error.pagenotfound.text": "الرابط الذي نقرت عليه قد يكون مكسورًا أو قد تكون الصفحة قد تمت إزالتها.",
"error.pagenotfound.text": "الرابط الذي نقرت عليه قد يكون معطوباً أو قد تكون الصفحة قد تمت إزالتها.",
"error.pagenotfound.title": "الصفحة غير موجودة",
"error.unauthorized.text": "أنت غير مخول لعرض هذه الصفحة.",
"error.unauthorized.title": "غير مخول",
Expand Down Expand Up @@ -59,6 +61,7 @@
"label.none": "لا شيء",
"label.notifications": "إشعارات",
"label.or": "أو",
"label.staff": "مشرف",
"label.subscribe": "اشتراك",
"label.tags": "وسوم",
"label.unread": "غير مقروء",
Expand All @@ -81,6 +84,9 @@
"modal.deleteaccount.text": "<0>عند اختيارك حذف حسابك، سنمحو جميع معلوماتك الشخصية إلى الأبد. سيبقى المحتوى الذي قمت بنشره، ولكنه سيصبح مجهولًا.</0><1>هذه العملية لا رجعة فيها. <2>هل أنت متأكد؟</2></1>",
"modal.deletecomment.header": "حذف التعليق",
"modal.deletecomment.text": "هذه العملية لا رجعة فيها. <0>هل أنت متأكد؟</0>",
"modal.notifications.nonew": "لا يوجد اشعارات جديدة!",
"modal.notifications.previous": "الإشعارات السابقة",
"modal.notifications.unread": "إشعارات غير مقروءة",
"modal.showvotes.message.zeromatches": "لم يتم العثور على مستخدمين مطابقين لـ <0>{0}</0>.",
"modal.showvotes.query.placeholder": "ابحث عن المستخدمين بالاسم...",
"modal.signin.header": "تسجيل الدخول للمشاركة والتصويت",
Expand Down Expand Up @@ -121,12 +127,17 @@
"mysettings.notification.title": "استخدم اللوحة التالية لاختيار الأحداث التي ترغب في تلقي إشعارات عنها",
"mysettings.page.subtitle": "إدارة إعدادات ملفك الشخصي",
"mysettings.page.title": "الإعدادات",
"notification.leftcomment": "علق على",
"notification.newpost": "منشور جديد",
"page.backhome": "أعدني إلى <0>{0}</0> الصفحة الرئيسية.",
"page.notinvited.text": "لم نتمكن من العثور على حساب لبريدك الإلكتروني.",
"page.notinvited.title": "غير مدعو",
"page.pendingactivation.text": "لقد أرسلنا لك بريدًا إلكترونيًا يحتوي على رابط لتفعيل حسابك.",
"page.pendingactivation.text2": "يرجى التحقق من بريدك الوارد لتفعيله.",
"page.pendingactivation.title": "حسابك في انتظار التفعيل",
"showpost.comment.copylink.error": "فشل في نسخ رابط التعليق، يرجى نسخ عنوان URL للصفحة",
"showpost.comment.copylink.success": "تم نسخ رابط التعليق إلى الحافظة",
"showpost.comment.unknownhighlighted": "معرف التعليق غير صالح #{id}",
"showpost.commentinput.placeholder": "اترك تعليقاً",
"showpost.discussionpanel.emptymessage": "لم يقم أحد بالتعليق بعد.",
"showpost.label.author": "نشر بواسطة <0/> · <1/>",
Expand All @@ -149,5 +160,5 @@
"signin.message.onlyadmins": "حاليًا مسموح فقط بتسجيل الدخول إلى حساب مسؤول",
"signin.message.private.text": "إذا كان لديك حساب أو دعوة، يمكنك استخدام الخيارات التالية لتسجيل الدخول.",
"signin.message.private.title": "<0>{0}</0> مساحة خاصة، يجب عليك تسجيل الدخول للمشاركة والتصويت.",
"{count, plural, one {# وسم} other {# وسوم}}": "{count, plural, one {# وسم} other {# وسوم}}"
}
"{count, plural, one {# tag} other {# tags}}": "{count, plural, one {# وسم} other {# وسوم}}"
}
Loading