Itumọ Awọn ohun elo PyGObject si Awọn Ede Yatọ - Apakan 5


A tẹsiwaju jara siseto PyGObject pẹlu rẹ ati nibi ni apakan 5th yii, a yoo kọ bi a ṣe le tumọ awọn ohun elo PyGObject wa si awọn ede oriṣiriṣi. Itumọ awọn ohun elo rẹ ṣe pataki ti o ba fẹ gbejade fun agbaye, yoo jẹ ọrẹ alabara diẹ sii fun awọn olumulo ipari nitori kii ṣe gbogbo eniyan loye Gẹẹsi.

Bawo ni Ilana Itumọ Ṣiṣẹ

A le ṣe akopọ awọn igbesẹ ti itumọ eyikeyi eto labẹ tabili Linux nipa lilo awọn igbesẹ wọnyi:

  1. Fa awọn okun ti o le tumọ jade lati faili Python.
  2. Fipamọ awọn okun sinu faili .pot eyiti o jẹ ọna kika ti o fun ọ laaye lati tumọ rẹ nigbamii si awọn ede miiran.
  3. Bẹrẹ itumọ awọn okun naa.
  4. Firanṣẹ awọn okun titun ti a tumọ si faili .po eyiti yoo lo ni adaṣe nigbati ede eto ba yipada.
  5. Ṣafikun diẹ ninu awọn ayipada eto eto si faili Python akọkọ ati faili .desktop .

Ati pe iyẹn ni! Lẹhin ṣiṣe awọn igbesẹ wọnyi ohun elo rẹ yoo ṣetan fun lilo fun awọn olumulo ipari lati gbogbo agbala aye (yoo .. O ni lati tumọ eto rẹ si gbogbo awọn ede kakiri agbaiye, botilẹjẹpe!), Awọn ohun rọrun ko ṣe? :-)

Ni akọkọ, lati fi akoko diẹ pamọ, ṣe igbasilẹ awọn faili iṣẹ akanṣe lati ọna asopọ isalẹ ki o jade faili ni itọsọna ile rẹ.

  1. https://copy.com/TjyZAaNgeQ6BB7yn

Ṣii faili\" setup.py " ki o ṣe akiyesi awọn ayipada ti a ṣe:

# 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.

Tun ṣii faili\" myprogram " ki o wo awọn ayipada eto eto ti a ṣe, gbogbo awọn ayipada ni a ṣalaye ninu awọn asọye naa:

#!/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()

Bayi .. Jẹ ki a bẹrẹ itumọ eto wa. Ni akọkọ ṣẹda faili .pot (faili kan ti o ni gbogbo awọn okun ti o le tumọ si ninu eto naa) ki iwọ
le bẹrẹ itumọ ni lilo pipaṣẹ atẹle:

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

Eyi yoo ṣẹda faili\" myprogram.pot " inu folda\" po " ninu folda iṣẹ akọkọ eyiti o ni koodu atẹle:

# 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 ""

Bayi lati bẹrẹ bẹrẹ itumọ awọn okun .. Ṣẹda faili ti o ya sọtọ fun ede kọọkan ti o fẹ lati tumọ eto rẹ si lilo awọn koodu awọn ede\" ISO-639-1 " inu\" po ”folda, fun apẹẹrẹ, ti o ba fẹ tumọ eto rẹ si Arabic , ṣẹda faili ti a pe ni \" ar.po "ki o daakọ awọn akoonu naa lati faili\" myprogram.pot " si.

Ti o ba fẹ lati tumọ eto rẹ si Jẹmánì , ṣẹda faili\" de.po " ki o daakọ awọn akoonu inu\" myprogram.pot ”Faili si rẹ .. ati bẹ ọkan, o gbọdọ ṣẹda faili fun ede kọọkan ti o fẹ lati tumọ eto rẹ si.

Bayi, a yoo ṣiṣẹ lori faili\" ar.po ", daakọ awọn akoonu inu faili\" myprogram.pot " ki o fi sii inu faili naa ki o ṣatunkọ atẹle naa:

  1. ÀK SOMK T Àlàyé DESBERUN : o le tẹ akọle iṣẹ rẹ nibi ti o ba fẹ.
  2. ỌDUN TI IDIMỌ IDAGBASOKE PACKAGE’s HOLDER : rọpo rẹ pẹlu ọdun ti o ti ṣẹda iṣẹ naa.
  3. PACKAGE : rọpo pẹlu orukọ ti apo-iwe.
  4. AKOKU AKANJU <[imeeli to ni idaabobo]>, YEAR : rọpo eyi pẹlu orukọ gidi rẹ, Imeeli ati ọdun ti o tumọ faili naa.
  5. PACKAGE VERSION : rọpo rẹ pẹlu ẹya package lati faili debian/Iṣakoso.
  6. YEAR-MO-DA HO: MI + ZONE : ko nilo alaye, o le yipada si eyikeyi ọjọ ti o fẹ.
  7. ORUKO TULLTUN <[imeeli & # 160; ni idaabobo]> : tun ropo orukọ rẹ ati Imeeli rẹ.
  8. Egbe-Egbe : rọpo pẹlu orukọ ede ti o ntumọ si, fun apẹẹrẹ\"Arabic" tabi\"Faranse".
  9. Ede : nibi, o gbọdọ fi koodu ISO-639-1 sii fun ede ti o ntumọ si, fun apẹẹrẹ\"ar",\"fr",\"de" ..etc, o le wa atokọ pipe nibi.
  10. CHARSET : Igbesẹ yii ṣe pataki, rọpo okun yii pẹlu\"UTF-8" (laisi awọn agbasọ) eyiti o ṣe atilẹyin awọn ede pupọ.

Bayi bẹrẹ itumọ! Ṣafikun itumọ rẹ fun okun kọọkan lẹhin awọn agbasọ ọrọ ni\" msgstr ". Fi faili naa pamọ ki o si jade. Faili itumọ ti o dara fun
Ede Larubawa gẹgẹbi apẹẹrẹ yẹ ki o dabi eleyi:

# 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 "اضغط عليّ لفتح الطرفية"

Ko si ohunkan diẹ sii lati ṣe, kan package eto naa nipa lilo pipaṣẹ wọnyi:

$ debuild -us -uc

Bayi gbiyanju lati fi sori ẹrọ package tuntun ti a ṣẹda nipa lilo pipaṣẹ atẹle.

$ sudo dpkg -i myprogram_1.0_all.deb

Ati pe yi ede eto pada nipa lilo eto\" Atilẹyin Ede " tabi lilo eyikeyi eto miiran si Arabic (tabi ede ti o ti tumọ faili rẹ si):

Lẹhin yiyan, eto rẹ yoo tumọ si ede Arabu.

Eyi ni ipari jara wa nipa siseto PyGObject fun tabili Linux, nitorinaa ọpọlọpọ awọn ohun miiran lo wa ti o le kọ lati inu itọkasi Python GI API ..

Kini o ro nipa jara? Ṣe o rii pe o wulo? Ṣe o ni anfani lati ṣẹda ohun elo akọkọ rẹ nipasẹ titẹle jara yii? Pin wa rẹ ero!