在kivy应用程序的标签文本中使用孟加拉语言 [英] using bangla language in label text of kivy app

查看:80
本文介绍了在kivy应用程序的标签文本中使用孟加拉语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在标签中添加孟加拉文字.我为此使用了几种字体.在这里,我使用了kalpurush.ttf.孟加拉文字显示良好.但是孟加拉字母的顺序有些问题.我写了তিন"但它显示-ত"也未显示连词.和ি"符号应在ত"之前,但在此之后.我正在使用pydroid应用程序.

i want to add bangla text in a label. im using several font for this. here i used kalpurush.ttf. the bangla text is showing well. but some problem with sequence of bangla letter. i wrote "তিন আস্তানা মাস্তান"। but it shows- "ত িন আসতানা মাসতান" its not showing the conjunct word also. and "ি" sign should be before "ত" but here its after. I'm using pydroid app.

在kivy启动器中,当我使用英语以外的任何其他字体时,它会崩溃.因此kivy启动器不支持任何其他字体.

in kivy launcher when i use any other font than english it just crashes. so kivy launcher doesnt support any other font.

我只想知道孟加拉文字在PC上运行时的外观.但我没有电脑.

i just want to know how does bangla text look like when running it in a pc. but i have no pc.

anoyone可以在PC上运行此代码并给我截图吗?我只需要知道bangla字体在kivy中显示得很好.因为我必须用我的母语(孟加拉语)制作一个android应用程序

can anoyone run this code on pc please and give me screenshot? i just need to know does bangla font shows well in kivy. cause i have to make an android app in my native language(bangla)

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder

Builder.load_string('''

<hello>:
    Label:
        text:"তিন অাস্তানা মাস্তান"
        font_name:"kalpurush.ttf" #please download this font

''')

class hello(BoxLayout):
    pass

class go(App):
    def build(self):
        return hello()

go().run()

推荐答案

我们可以使用[font] [/font]标签在同一Label小部件中使用Bangla ANSI文本和英文文本.像这样(用kv语言):

We can use [font][/font] tag to use Bangla ANSI text with English text in same Label widget. Like this (in kv language):

    text = "[font=font/SutonnyMJ]Avwg evsjvq K_v ewj[/font] means I speak Bangla"

但是如何生成带有字体标签的(英语和孟加拉语混合)文本? 此github存储库提供了一种解决方案:

But how to generate (English and Bangla mixed) text with font tag? This github repo provides a solution:

def toBijoy(str):
    def isEnglish(s):
        return s.isascii()
    import converter
    test = converter.Unicode()
    b_flag = 0
    ftext = ""
    temp = ''
    for char in str:
        if char == ' ' and b_flag == 0:
            ftext += char
        elif char == ' ' and b_flag == 1:
            temp += char
        elif isEnglish(char) is False:
            if b_flag == 0:
                temp += "কর্ড [font=font/SutonnyMJ]" + char
                b_flag = 1
            else:
                temp += char
        else:
            if b_flag == 1:
                temp = test.convertUnicodeToBijoy(temp)
                temp = temp[4:] + "[/font]" + char
                ftext += temp
                b_flag = 0
                temp = ''
            else:
                ftext += char

    return ftext

现在,我们可以转换文本(带有字体标签),使用id调用小部件,然后分配格式化的文本.

Now we can convert the text (with font tags), call an widget using id, and then assign formatted text.

self.ids.bangla_mixed_text.markup = True
self.ids.bangla_mixed_text.text = toBijoy(str)

在kv语言中,我们需要执行以下操作:

In kv language we need to do something like this:

Label:
    id: bangla_mixed_text
    text: ''

回购中的更多详细信息.

More details in the repo.

这篇关于在kivy应用程序的标签文本中使用孟加拉语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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