Fassara Aikace-aikacen PyGObject zuwa Harsuna daban-daban - Sashe na 5


Muna ci gaba da shirin PyGObject tare da ku kuma a nan a cikin wannan 5th kashi, za mu koyi yadda ake fassara aikace-aikacen mu na PyGObject zuwa harsuna daban-daban. Fassara aikace-aikacenku yana da mahimmanci idan za ku buga shi don duniya, zai zama mafi aminci ga masu amfani da ƙarshen saboda ba kowa ya fahimci Turanci ba.

Yadda Tsarin Fassara ke Aiki

Za mu iya taƙaita matakan fassarar kowane shiri a ƙarƙashin tebur na Linux ta amfani da waɗannan matakan:

  1. Cire igiyoyin da za a iya fassarawa daga fayil ɗin Python.
  2. Ajiye kirtani cikin fayil .pot wanda shine tsari wanda zai baka damar fassara shi daga baya zuwa wasu harsuna.
  3. Fara fassarar zaren.
  4. Fitar da sabbin igiyoyin da aka fassara zuwa fayil ɗin .po waɗanda za a yi amfani da su ta atomatik lokacin da aka canza harshen tsarin.
  5. Ƙara wasu ƙananan canje-canje na shirye-shirye zuwa babban fayil ɗin Python da fayil ɗin .desktop.

Kuma shi ke nan! Bayan yin waɗannan matakan aikace-aikacenku zai kasance a shirye don amfani don masu amfani na ƙarshe daga ko'ina cikin duniya (zai.. Dole ne ku fassara shirin ku zuwa duk harsunan duniya, ko da yake !), Sauti mai sauƙi ba haka ba? :-)

Na farko, don adana ɗan lokaci, zazzage fayilolin aikin daga mahaɗin ƙasa kuma cire fayil ɗin a cikin kundin adireshi na gida.

  1. https://copy.com/TjyZAaNgeQ6BB7yn

Bude fayil ɗin \setup.py kuma lura da canje-canjen da muka yi:

# Here we imported the 'setup' module which allows us to install Python scripts to the local system beside performing some other tasks, you can find the documentation here: https://docs.python.org/2/distutils/apiref.html
from distutils.core import setup

# Those modules will help us in creating the translation files for the program automatically.
from subprocess import call
from glob import glob
from os.path import splitext, split

# DON'T FOTGET TO REPLACE 'myprogram' WITH THE NAME OF YOUR PROGRAM IN EVERY FILE IN THIS PROJECT.

data_files = [ ("lib/myprogram", ["ui.glade"]), # This is going to install the "ui.glade" file under the /usr/lib/myprogram path.
                     ("share/applications", ["myprogram.desktop"]) ] 

# This code does everything needed for creating the translation files, first it will look for all the .po files inside the po folder, then it will define the default path for where to install the translation files (.mo) on the local system, then it's going to create the directory on the local system for the translation files of our program and finally it's going to convert all the .po files into .mo files using the "msgfmt" command.
po_files = glob("po/*.po")
for po_file in po_files:
  lang = splitext(split(po_file)[1])[0]
  mo_path = "locale/{}/LC_MESSAGES/myprogram.mo".format(lang)
# Make locale directories
  call("mkdir -p locale/{}/LC_MESSAGES/".format(lang), shell=True)
# Generate mo files
  call("msgfmt {} -o {}".format(po_file, mo_path), shell=True)
  locales = map(lambda i: ('share/'+i, [i+'/myprogram.mo', ]), glob('locale/*/LC_MESSAGES'))

# Here, the installer will automatically add the .mo files to the data files to install them later.
  data_files.extend(locales)

setup(name = "myprogram", # Name of the program.
      version = "1.0", # Version of the program.
      description = "An easy-to-use web interface to create & share pastes easily", # You don't need any help here.
      author = "TecMint", # Nor here.
      author_email = "[email ",# Nor here :D
      url = "http://example.com", # If you have a website for you program.. put it here.
      license='GPLv3', # The license of the program.
      scripts=['myprogram'], # This is the name of the main Python script file, in our case it's "myprogram", it's the file that we added under the "myprogram" folder.

# Here you can choose where do you want to install your files on the local system, the "myprogram" file will be automatically installed in its correct place later, so you have only to choose where do you want to install the optional files that you shape with the Python script
      data_files=data_files) # And this is going to install the .desktop file under the /usr/share/applications folder, all the folder are automatically installed under the /usr folder in your root partition, you don't need to add "/usr/ to the path.

Hakanan buɗe fayil ɗin \myprogram kuma duba canje-canjen shirin da muka yi, duk canje-canjen an bayyana su a cikin sharhi:

#!/usr/bin/python 
# -*- coding: utf-8 -*- 

## Replace your name and email.
# My Name <[email >

## Here you must add the license of the file, replace "MyProgram" with your program name.
# License:
#    MyProgram is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    MyProgram is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with MyProgram.  If not, see <http://www.gnu.org/licenses/>.

from gi.repository import Gtk 
import os, gettext, locale

## This is the programmatic change that you need to add to the Python file, just replace "myprogram" with the name of your program. The "locale" and "gettext" modules will take care about the rest of the operation.
locale.setlocale(locale.LC_ALL, '')
gettext.bindtextdomain('myprogram', '/usr/share/locale')
gettext.textdomain('myprogram')
_ = gettext.gettext
gettext.install("myprogram", "/usr/share/locale")

class Handler: 
  
  def openterminal(self, button): 
    ## When the user clicks on the first button, the terminal will be opened.
    os.system("x-terminal-emulator ")
  
  def closeprogram(self, button):
    Gtk.main_quit()
    
# Nothing new here.. We just imported the 'ui.glade' file. 
builder = Gtk.Builder() 
builder.add_from_file("/usr/lib/myprogram/ui.glade") 
builder.connect_signals(Handler()) 

label = builder.get_object("label1")
# Here's another small change, instead of setting the text to ("Welcome to my Test program!") we must add a "_" char before it in order to allow the responsible scripts about the translation process to recognize that it's a translatable string.
label.set_text(_("Welcome to my Test program !"))

button = builder.get_object("button2")
# And here's the same thing.. You must do this for all the texts in your program, elsewhere, they won't be translated.
button.set_label(_("Click on me to open the Terminal"))


window = builder.get_object("window1") 
window.connect("delete-event", Gtk.main_quit)
window.show_all() 
Gtk.main()

Yanzu .. Bari mu fara fassara shirin mu. Da farko ka ƙirƙiri fayil ɗin .pot (fayil ɗin da ke ɗauke da duk igiyoyin da za a iya fassarawa a cikin shirin) domin ku
na iya fara fassara ta amfani da umarni mai zuwa:

$ cd myprogram
$ xgettext --language=Python --keyword=_ -o po/myprogram.pot myprogram

Wannan zai haifar da fayil ɗin \myprogram.pot a cikin babban fayil ɗin \po a cikin babban fayil ɗin aikin wanda ya ƙunshi lambar mai zuwa:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <[email >, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-12-29 21:28+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <[email >\n"
"Language-Team: LANGUAGE <[email >\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: myprogram:48
msgid "Welcome to my Test program !"
msgstr ""

#: myprogram:52
msgid "Click on me to open the Terminal"
msgstr ""

Yanzu don fara fassarar kirtani >po” babban fayil, misali, idan kuna son fassara shirin ku zuwa Larabci, ƙirƙirar fayil mai suna \ar.po sannan ku kwafi abubuwan da ke ciki. daga fayil ɗin \myprogram.pot zuwa gare shi.

Idan kuna son fassara shirin ku zuwa Jamus, ƙirƙirar fayil ɗin \de.po sannan ku kwafi abubuwan da ke cikin \myprogram.pot >” fayil zuwa gare shi.. don haka ɗaya, dole ne ku ƙirƙiri fayil don kowane harshe da kuke son fassara shirin ku.

Yanzu, za mu yi aiki a kan fayil ɗin \ar.po, kwafi abin da ke ciki daga fayil ɗin \myprogram.pot sannan mu sanya shi cikin wannan fayil ɗin sannan a gyara shi. masu zuwa:

  1. WASU BAYANIN TAKEN: zaku iya shigar da taken aikinku anan idan kuna so.
  2. SHEKARAR KASHIN KYAUTA: maye gurbinta da shekarar da kuka ƙirƙiri aikin.
  3. PACKAGE: maye gurbin shi da sunan kunshin.
  4. Marubuci na farko <[email >, SHEKARA: maye gurbin wannan da ainihin sunanka, Imel da shekarar da ka fassara fayil ɗin.
  5. PACKAGE VERSION: maye gurbin shi da sigar fakitin daga fayil ɗin debian/control.
  6. YEAR-MO-DA HO:MI+ZONE: baya buƙatar bayani, kuna iya canza shi zuwa kowace ranar da kuke so.
  7. CIKAKKEN SUNA <[email >: kuma musanya shi sunanka da Imel ɗinka.
  8. Ƙungiyar Harshe: maye gurbin shi da sunan harshen da kuke fassarawa, misali \Larabci ko Faransa.
  9. Harshe: anan, dole ne ka saka lambar ISO-639-1 don harshen da kake fassarawa, misali \ar, \fr, \de ..da sauransu, zaku iya samun cikakken lissafin anan.
  10. CHASET: wannan matakin yana da mahimmanci, musanya wannan kirtani da \UTF-8 (ba tare da ambato ba) wanda ke goyan bayan yawancin harsuna.

Yanzu fara fassara! Ƙara fassarar ku ga kowane kirtani bayan abubuwan da aka ambata a cikin \msgstr Ajiye fayil ɗin kuma fita. Fayil ɗin fassara mai kyau don
Ya kamata harshen Larabci ya zama misali kamar haka:

# My Program
# Copyright (C) 2014
# This file is distributed under the same license as the myprogram package.
# Hanny Helal <[email <, 2014.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: 1.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-12-29 21:28+0200\n"
"PO-Revision-Date: 2014-12-29 22:28+0200\n"
"Last-Translator: M.Hanny Sabbagh <hannysabbagh<@hotmail.com<\n"
"Language-Team: Arabic <[email <\n"
"Language: ar\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: myprogram:48
msgid "Welcome to my Test program !"
msgstr "أهلًا بك إلى برنامجي الاختباري!"

#: myprogram:52
msgid "Click on me to open the Terminal"
msgstr "اضغط عليّ لفتح الطرفية"

Babu wani abin da za a yi, kawai haɗa shirin ta amfani da umarni mai zuwa:

$ debuild -us -uc

Yanzu gwada shigar da sabon fakitin da aka ƙirƙira ta amfani da umarni mai zuwa.

$ sudo dpkg -i myprogram_1.0_all.deb

Kuma canza yaren tsarin ta amfani da shirin \Language Support ko amfani da kowane shiri zuwa Larabci (ko harshen da kuka fassara fayil ɗinku zuwa):

Bayan zaɓar, za a fassara shirin ku zuwa harshen Larabci.

Anan ya ƙare jerin mu game da shirye-shiryen PyGObject don tebur na Linux, ba shakka akwai wasu abubuwa da yawa waɗanda za ku iya koya daga ma'anar Python GI API.

Me kuke tunani game da jerin? Kuna ganin yana da amfani? Shin kun sami damar ƙirƙirar aikace-aikacenku na farko ta bin wannan jerin? Raba mana ra'ayoyin ku!