在kivymd中使用arabic_reshaper和bidi.algorithm [英] Using arabic_reshaper and bidi.algorithm in kivymd

查看:87
本文介绍了在kivymd中使用arabic_reshaper和bidi.algorithm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用kivymd制作一个应用程序,其中包含阿拉伯语和波斯语文本. 根据我的搜索,要执行此操作,应使用arabic_reshaper和bidi.algorithm,还应使用支持波斯和阿拉伯语言的字体. 结果,我能够编写这样的代码,并且它很好地支持波斯语和阿拉伯语文本.

I am going to make a application with kivymd, which contains Arabic and Persian texts. According to my searches, to do this, you should use arabic_reshaper and bidi.algorithm and also use a font that supports Persian and Arabic languages. As a result, I was able to write the code like this, and it supports both Persian and Arabic text well.

import kivy.app
import kivy.uix.label
import arabic_reshaper
import bidi.algorithm

class TestApp(kivy.app.App):
 def build(self):
    
    bidi_text = bidi.algorithm.get_display(arabic_reshaper.reshape("میلاد"))
    return kivy.uix.label.Label(text=bidi_text, font_name="arial" , font_size="90sp") 

testApp = TestApp()
testApp.run()

查看输出结果

现在,我的问题是我想按以下方式编写程序,在此方法中,我可以更改字体,但是不能使用arabic_reshaper和bidi.algorithm方法,这将导致输出文本显示在这样.

Now, My problem is that I want to code my program as follows, in this method I can change the font, but I can not use the method arabic_reshaper and bidi.algorithm, and this causes the output text to be displayed in this way .

                from kivymd.app import MDApp
                from kivymd.uix.screen import Screen
                from kivymd.uix.label import MDLabel
                from kivy.lang import Builder
                import arabic_reshaper
                import bidi.algorithm


                screen_helper_up = """
                Screen:
                    NavigationLayout:
                        ScreenManager:
                            Screen:
                                BoxLayout:
                                    orientation: 'vertical'
                                    MDToolbar:
                                        title: 'میلاد'
                                        font_name:'arial.ttf'
                                        left_action_items: [["menu", lambda x: nav_drawer.toggle_nav_drawer()]]
                                        
                                        elevation:10

                                    Widget:
                                    Label:
                                        text: "میلاد"
                                        font_name:'arial.ttf'
                                        markup: True
                                        font_size: 100
                                        color: 0,0,0,1

                        MDNavigationDrawer:
                            id: nav_drawer
                        
                """

                class DemoApp (MDApp):

                    
                    
                    def build(self):
                        
                        screen = Screen()
                        screen = Builder.load_string(screen_helper_up)
                        return screen

                    

                DemoApp().run()

如下图所示,仅在Label和MDToolbar标题中更改了字体,不幸的是,字体也未更改.

As you can see in the image below, the font has changed only in Label and in MDToolbar title, Unfortunately, the font has not changed either.

查看输出结果

请指导我:

1-如何使用...和...方法在上述代码中显示波斯语和阿拉伯语文本?

1- How can I use the ... and ... methods to display Persian and Arabic text in the above code?

2-如何更改...中的字体?

2- How can I change the font in ...?

感谢您的关注

推荐答案

这就是我所做的:在Kv语言中,将文本引用到主应用程序中的变量(app.res3):

This is what I have done: In the Kv language, refer the text to a variable (app.res3) in the main app:

`text:app.res3`

`font_name:'PTBLDHAD'`  

在主应用中,我按如下方式应用了整形器模块:

In the main app, I applied the reshaper module as follows:

`text3 = ("الصفحة الرئيسية")` 

reshaped_texts3 = arabic_reshaper.reshape(text3)

res3 = get_display(reshaped_texts3)

这篇关于在kivymd中使用arabic_reshaper和bidi.algorithm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆