PyGObject ആപ്ലിക്കേഷനുകൾ വ്യത്യസ്ത ഭാഷകളിലേക്ക് വിവർത്തനം ചെയ്യുന്നു - ഭാഗം 5


ഞങ്ങൾ നിങ്ങളോടൊപ്പം PyGObject പ്രോഗ്രാമിംഗ് സീരീസ് തുടരുന്നു, ഇവിടെ ഈ 5-ാം ഭാഗത്ത്, ഞങ്ങളുടെ PyGObject ആപ്ലിക്കേഷനുകൾ എങ്ങനെ വ്യത്യസ്ത ഭാഷകളിലേക്ക് വിവർത്തനം ചെയ്യാമെന്ന് ഞങ്ങൾ പഠിക്കും. നിങ്ങളുടെ ആപ്ലിക്കേഷനുകൾ ലോകത്തിനായി പ്രസിദ്ധീകരിക്കാൻ പോകുകയാണെങ്കിൽ അത് വിവർത്തനം ചെയ്യുന്നത് പ്രധാനമാണ്, എല്ലാവർക്കും ഇംഗ്ലീഷ് മനസ്സിലാകാത്തതിനാൽ അന്തിമ ഉപയോക്താക്കൾക്ക് ഇത് കൂടുതൽ ഉപയോക്തൃ സൗഹൃദമായിരിക്കും.

വിവർത്തന പ്രക്രിയ എങ്ങനെ പ്രവർത്തിക്കുന്നു

ലിനക്സ് ഡെസ്ക്ടോപ്പിന് കീഴിലുള്ള ഏത് പ്രോഗ്രാമും വിവർത്തനം ചെയ്യുന്നതിനുള്ള ഘട്ടങ്ങൾ ഈ ഘട്ടങ്ങൾ ഉപയോഗിച്ച് നമുക്ക് സംഗ്രഹിക്കാം:

  1. പൈത്തൺ ഫയലിൽ നിന്ന് വിവർത്തനം ചെയ്യാവുന്ന സ്ട്രിംഗുകൾ എക്uസ്uട്രാക്റ്റ് ചെയ്യുക.
  2. സ്uട്രിംഗുകൾ ഒരു .pot ഫയലിലേക്ക് സംരക്ഷിക്കുക, അത് പിന്നീട് മറ്റ് ഭാഷകളിലേക്ക് വിവർത്തനം ചെയ്യാൻ നിങ്ങളെ അനുവദിക്കുന്ന ഫോർമാറ്റാണ്.
  3. സ്ട്രിംഗുകൾ വിവർത്തനം ചെയ്യാൻ ആരംഭിക്കുക.
  4. സിസ്റ്റം ഭാഷ മാറ്റുമ്പോൾ സ്വയമേവ ഉപയോഗിക്കുന്ന ഒരു .po ഫയലിലേക്ക് പുതിയ വിവർത്തനം ചെയ്ത സ്ട്രിംഗുകൾ എക്uസ്uപോർട്ട് ചെയ്യുക.
  5. പ്രധാന പൈത്തൺ ഫയലിലേക്കും .desktop ഫയലിലേക്കും ചില ചെറിയ പ്രോഗ്രാമാമാറ്റിക് മാറ്റങ്ങൾ ചേർക്കുക.

അത്രമാത്രം! ഈ ഘട്ടങ്ങൾ പൂർത്തിയാക്കിയ ശേഷം, നിങ്ങളുടെ ആപ്ലിക്കേഷൻ ലോകമെമ്പാടുമുള്ള അന്തിമ ഉപയോക്താക്കൾക്ക് ഉപയോഗിക്കുന്നതിന് തയ്യാറാകും (നിങ്ങളുടെ പ്രോഗ്രാം ലോകമെമ്പാടുമുള്ള എല്ലാ ഭാഷകളിലേക്കും വിവർത്തനം ചെയ്യണം, എന്നിരുന്നാലും!), ഇത് എളുപ്പമാണെന്ന് തോന്നുന്നു, അല്ലേ? :-)

ആദ്യം, കുറച്ച് സമയം ലാഭിക്കുന്നതിന്, താഴെയുള്ള ലിങ്കിൽ നിന്ന് പ്രോജക്റ്റ് ഫയലുകൾ ഡൗൺലോഡ് ചെയ്ത് നിങ്ങളുടെ ഹോം ഡയറക്uടറിയിൽ നിന്ന് ഫയൽ എക്uസ്uട്രാക്uറ്റ് ചെയ്യുക.

  1. https://copy.com/TjyZAaNgeQ6BB7yn

\setup.py ഫയൽ തുറന്ന് ഞങ്ങൾ ചെയ്ത മാറ്റങ്ങൾ ശ്രദ്ധിക്കുക:

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

\myprogram ഫയൽ തുറന്ന് ഞങ്ങൾ ചെയ്ത പ്രോഗ്രാമാമാറ്റിക് മാറ്റങ്ങൾ കാണുക, എല്ലാ മാറ്റങ്ങളും അഭിപ്രായങ്ങളിൽ വിശദീകരിച്ചിരിക്കുന്നു:

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

ഇനി.. നമുക്ക് നമ്മുടെ പ്രോഗ്രാം വിവർത്തനം ചെയ്യാൻ തുടങ്ങാം. ആദ്യം .pot ഫയൽ സൃഷ്uടിക്കുക (പ്രോഗ്രാമിലെ വിവർത്തനം ചെയ്യാവുന്ന എല്ലാ സ്uട്രിംഗുകളും അടങ്ങുന്ന ഒരു ഫയൽ) നിങ്ങൾ
ഇനിപ്പറയുന്ന കമാൻഡ് ഉപയോഗിച്ച് വിവർത്തനം ആരംഭിക്കാൻ കഴിയും:

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

ഇത് ഇനിപ്പറയുന്ന കോഡ് അടങ്ങുന്ന പ്രധാന പ്രോജക്റ്റ് ഫോൾഡറിലെ \po ഫോൾഡറിനുള്ളിൽ \myprogram.pot ഫയൽ സൃഷ്ടിക്കാൻ പോകുന്നു:

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

ഇപ്പോൾ സ്ട്രിംഗുകൾ വിവർത്തനം ചെയ്യാൻ ആരംഭിക്കുന്നതിന്.. \ISO-639-1 ഭാഷാ കോഡുകൾ ഉപയോഗിച്ച് നിങ്ങളുടെ പ്രോഗ്രാം വിവർത്തനം ചെയ്യാൻ ആഗ്രഹിക്കുന്ന ഓരോ ഭാഷയ്ക്കും ഒരു പ്രത്യേക ഫയൽ സൃഷ്ടിക്കുക. >po” ഫോൾഡർ, ഉദാഹരണത്തിന്, നിങ്ങളുടെ പ്രോഗ്രാം അറബിക്കിലേക്ക് വിവർത്തനം ചെയ്യണമെങ്കിൽ, \ar.po എന്ന പേരിൽ ഒരു ഫയൽ സൃഷ്uടിച്ച് ഉള്ളടക്കം പകർത്തുക. \myprogram.pot” ഫയലിൽ നിന്ന് അതിലേക്ക്.

നിങ്ങളുടെ പ്രോഗ്രാം ജർമ്മൻ ഭാഷയിലേക്ക് വിവർത്തനം ചെയ്യണമെങ്കിൽ, \de.po ഫയൽ സൃഷ്uടിച്ച് \myprogram.potൽ നിന്ന് ഉള്ളടക്കങ്ങൾ പകർത്തുക >” അതിലേക്കുള്ള ഫയൽ.. അങ്ങനെ ഒന്ന്, നിങ്ങളുടെ പ്രോഗ്രാം വിവർത്തനം ചെയ്യാൻ ആഗ്രഹിക്കുന്ന ഓരോ ഭാഷയ്ക്കും നിങ്ങൾ ഒരു ഫയൽ സൃഷ്ടിക്കണം.

ഇപ്പോൾ, ഞങ്ങൾ \ar.po ഫയലിൽ പ്രവർത്തിക്കും, \myprogram.pot ഫയലിൽ നിന്ന് ഉള്ളടക്കങ്ങൾ പകർത്തി ആ ഫയലിനുള്ളിൽ ഇടുക, എഡിറ്റ് ചെയ്യുക ഇനിപ്പറയുന്നവ:

  1. ചില വിവരണാത്മക ശീർഷകം: നിങ്ങൾക്ക് വേണമെങ്കിൽ നിങ്ങളുടെ പ്രോജക്റ്റിന്റെ ശീർഷകം ഇവിടെ നൽകാം.
  2. പാക്കേജിന്റെ പകർപ്പവകാശ ഉടമ: നിങ്ങൾ പ്രോജക്റ്റ് സൃഷ്uടിച്ച വർഷം ഉപയോഗിച്ച് അത് മാറ്റിസ്ഥാപിക്കുക.
  3. പാക്കേജ്: പാക്കേജിന്റെ പേര് ഉപയോഗിച്ച് അത് മാറ്റിസ്ഥാപിക്കുക.
  4. ആദ്യ ലേഖകൻ <[ഇമെയിൽ സംരക്ഷിത]>, വർഷം: നിങ്ങളുടെ യഥാർത്ഥ പേര്, ഇമെയിൽ, നിങ്ങൾ ഫയൽ വിവർത്തനം ചെയ്uത വർഷം എന്നിവ ഉപയോഗിച്ച് ഇത് മാറ്റിസ്ഥാപിക്കുക.
  5. പാക്കേജ് പതിപ്പ്: ഡെബിയൻ/കൺട്രോൾ ഫയലിൽ നിന്നുള്ള പാക്കേജ് പതിപ്പ് ഉപയോഗിച്ച് ഇത് മാറ്റിസ്ഥാപിക്കുക.
  6. YEAR-MO-DA HO:MI+ZONE: വിശദീകരണം ആവശ്യമില്ല, നിങ്ങൾക്കത് ഏത് തീയതിയിലേക്കും മാറ്റാം.
  7. പൂർണ്ണമായ പേര് <[email >: നിങ്ങളുടെ പേരും ഇമെയിലും പകരം വയ്ക്കുക.
  8. ഭാഷ-ടീം: നിങ്ങൾ വിവർത്തനം ചെയ്യുന്ന ഭാഷയുടെ പേര് പകരം വയ്ക്കുക, ഉദാഹരണത്തിന് \അറബിക് അല്ലെങ്കിൽ \ഫ്രഞ്ച്.
  9. ഭാഷ: ഇവിടെ, നിങ്ങൾ വിവർത്തനം ചെയ്യുന്ന ഭാഷയ്uക്കായി ISO-639-1 കോഡ് ചേർക്കണം, ഉദാഹരണത്തിന് \ar, \fr, \de ..തുടങ്ങിയവ, നിങ്ങൾക്ക് ഇവിടെ ഒരു പൂർണ്ണമായ ലിസ്റ്റ് കണ്ടെത്താം.
  10. CHARSET: ഈ ഘട്ടം പ്രധാനമാണ്, മിക്ക ഭാഷകളെയും പിന്തുണയ്ക്കുന്ന \UTF-8 (ഉദ്ധരണികളില്ലാതെ) ഉപയോഗിച്ച് ഈ സ്ട്രിംഗ് മാറ്റിസ്ഥാപിക്കുക.

ഇപ്പോൾ വിവർത്തനം ആരംഭിക്കുക! \msgstr എന്നതിലെ ഉദ്ധരണികൾക്ക് ശേഷം ഓരോ സ്uട്രിംഗിനും നിങ്ങളുടെ വിവർത്തനം ചേർക്കുക. ഫയൽ സംരക്ഷിച്ച് പുറത്തുകടക്കുക.
എന്നതിനായുള്ള മികച്ച വിവർത്തന ഫയൽ അറബി ഭാഷ ഒരു ഉദാഹരണമായി ഇതുപോലെ ആയിരിക്കണം:

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

കൂടുതലായി ഒന്നും ചെയ്യാനില്ല, ഇനിപ്പറയുന്ന കമാൻഡ് ഉപയോഗിച്ച് പ്രോഗ്രാം പാക്കേജ് ചെയ്യുക:

$ debuild -us -uc

ഇപ്പോൾ താഴെ പറയുന്ന കമാൻഡ് ഉപയോഗിച്ച് പുതിയതായി സൃഷ്ടിച്ച പാക്കേജ് ഇൻസ്റ്റാൾ ചെയ്യാൻ ശ്രമിക്കുക.

$ sudo dpkg -i myprogram_1.0_all.deb

കൂടാതെ \ഭാഷാ പിന്തുണ പ്രോഗ്രാം ഉപയോഗിച്ചോ മറ്റേതെങ്കിലും പ്രോഗ്രാം ഉപയോഗിച്ച് അറബിക്കിലേക്കോ (അല്ലെങ്കിൽ നിങ്ങളുടെ ഫയൽ വിവർത്തനം ചെയ്uത ഭാഷയിലോ) സിസ്റ്റം ഭാഷ മാറ്റുക:

തിരഞ്ഞെടുത്ത ശേഷം, നിങ്ങളുടെ പ്രോഗ്രാം അറബി ഭാഷയിലേക്ക് വിവർത്തനം ചെയ്യപ്പെടും.

ലിനക്സ് ഡെസ്ക്ടോപ്പിനായുള്ള PyGObject പ്രോഗ്രാമിംഗിനെക്കുറിച്ചുള്ള ഞങ്ങളുടെ പരമ്പര ഇവിടെ അവസാനിക്കുന്നു, തീർച്ചയായും നിങ്ങൾക്ക് പൈത്തൺ GI API റഫറൻസിൽ നിന്ന് പഠിക്കാൻ കഴിയുന്ന മറ്റ് നിരവധി കാര്യങ്ങളുണ്ട്.

സീരിയലിനെക്കുറിച്ച് നിങ്ങൾക്ക് എന്താണ് തോന്നുന്നത്? നിങ്ങൾക്ക് ഇത് ഉപയോഗപ്രദമാണെന്ന് തോന്നുന്നുണ്ടോ? ഈ സീരീസ് പിന്തുടർന്ന് നിങ്ങളുടെ ആദ്യ ആപ്ലിക്കേഷൻ സൃഷ്ടിക്കാൻ നിങ്ങൾക്ക് കഴിഞ്ഞോ? നിങ്ങളുടെ ചിന്തകൾ ഞങ്ങളോട് പങ്കിടുക!