ການແປໂປແກມ PyGObject ເປັນພາສາທີ່ແຕກຕ່າງກັນ - ພາກທີ 5


ພວກເຮົາສືບຕໍ່ຊຸດການຂຽນໂປແກຼມ PyGObject ກັບທ່ານແລະທີ່ນີ້ໃນພາກ 5 ນີ້, ພວກເຮົາຈະຮຽນຮູ້ການແປພາສາໂປແກຼມ PyGObject ຂອງພວກເຮົາເປັນຫລາຍພາສາ. ການແປ ຄຳ ຮ້ອງສະ ໝັກ ຂອງທ່ານແມ່ນ ສຳ ຄັນຖ້າທ່ານຈະເຜີຍແຜ່ໃຫ້ທົ່ວໂລກ, ມັນຈະເປັນມິດ ສຳ ລັບຜູ້ ນຳ ໃຊ້ສຸດທ້າຍເພາະວ່າທຸກຄົນບໍ່ເຂົ້າໃຈພາສາອັງກິດ.

ຂະບວນການແປພາສາເຮັດວຽກແນວໃດ

ພວກເຮົາສາມາດສະຫຼຸບຂັ້ນຕອນຂອງການແປພາສາໂປແກຼມໃດ ໜຶ່ງ ພາຍໃຕ້ຄອມພິວເຕີ້ Linux ໂດຍໃຊ້ຂັ້ນຕອນເຫຼົ່ານີ້:

<

  • ສະກັດສາຍທີ່ແປໄດ້ຈາກແຟ້ມ Python.
  • ບັນທຶກເຊືອກໄວ້ເປັນເອກະສານ .pot ເຊິ່ງເປັນຮູບແບບທີ່ຊ່ວຍໃຫ້ທ່ານແປພາສາຕໍ່ມາເປັນພາສາອື່ນໆ.
  • ເລີ່ມຕົ້ນແປສັບສາຍ.
  • ສົ່ງອອກຊ່ອຍແນ່ ໃໝ່ໆ ທີ່ຖືກແປເປັນເອກະສານ .po ເຊິ່ງຈະຖືກ ນຳ ໃຊ້ໂດຍອັດຕະໂນມັດເມື່ອພາສາລະບົບຖືກປ່ຽນແປງ.
  • ເພີ່ມບາງການປ່ຽນແປງໂປແກຼມນ້ອຍໆໃສ່ແຟ້ມ Python ຕົ້ນຕໍແລະແຟ້ມ . ຄອມພິວເຕີ້ .
  • ນັ້ນແມ່ນມັນ! ຫຼັງຈາກປະຕິບັດຕາມຂັ້ນຕອນເຫຼົ່ານີ້ແລ້ວ ຄຳ ຮ້ອງສະ ໝັກ ຂອງທ່ານຈະກຽມພ້ອມ ສຳ ລັບການ ນຳ ໃຊ້ ສຳ ລັບຜູ້ ນຳ ໃຊ້ທີ່ມາຈາກທົ່ວທຸກມຸມໂລກ (ຈະ .. ທ່ານຕ້ອງໄດ້ແປໂປແກຼມຂອງທ່ານໃຫ້ທຸກໆພາສາທົ່ວໂລກ, ເຖິງແມ່ນວ່າ!), ຟັງງ່າຍບໍ່ແມ່ນບໍ? :-)

    ທຳ ອິດ, ເພື່ອປະຢັດເວລາ, ໃຫ້ດາວໂຫລດເອກະສານໂຄງການຈາກລິງຂ້າງລຸ່ມນີ້ແລະສະກັດເອກະສານເຂົ້າໃນໄດເລກະທໍລີບ້ານຂອງທ່ານ.

    <

  • 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 (ເອກະສານທີ່ປະກອບດ້ວຍສາຍແປທີ່ສາມາດແປໄດ້ທັງ ໝົດ ໃນໂປແກຼມ) ເພື່ອໃຫ້ທ່ານ
    ສາມາດເລີ່ມແປໂດຍໃຊ້ ຄຳ ສັ່ງຕໍ່ໄປນີ້:

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

    ນີ້ແມ່ນການສ້າງເອກະສານ“ myprogram.pot ” ພາຍໃນແຟ້ມ“ po ” ໃນໂຟນເດີຂອງໂຄງການຫຼັກເຊິ່ງປະກອບມີລະຫັດດັ່ງຕໍ່ໄປນີ້:

    # 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 ” ແລະ ສຳ ເນົາເນື້ອໃນຈາກ“ myprogram.pot ” ໃສ່ມັນ.

    ຖ້າທ່ານຕ້ອງການແປໂປຣແກຣມຂອງທ່ານເປັນ ເຢຍລະມັນ , ສ້າງເອກະສານ“ de.po ” ແລະ ສຳ ເນົາເນື້ອໃນຈາກ“ myprogram.pot ” file to it .. ແລະດັ່ງນັ້ນ, ທ່ານຕ້ອງສ້າງແຟ້ມ ສຳ ລັບແຕ່ລະພາສາທີ່ທ່ານຕ້ອງການແປໂປຣແກຣມຂອງທ່ານ.

    ດຽວນີ້, ພວກເຮົາຈະເຮັດວຽກກ່ຽວກັບເອກະສານ“ ar.po ”, ຄັດລອກເນື້ອຫາຈາກເອກະສານ“ myprogram.pot ” ແລະໃສ່ໃນເອກະສານນັ້ນແລະດັດແກ້ຕໍ່ໄປນີ້ :

    <

  • ບາງ ຄຳ ອະທິບາຍກ່ຽວກັບຫົວຂໍ້ : ທ່ານສາມາດໃສ່ຫົວຂໍ້ຂອງໂຄງການຂອງທ່ານໄດ້ທີ່ນີ້ຖ້າທ່ານຕ້ອງການ.
  • ປີປີທີ່ຜູ້ປົກຄອງພິເສດຕອບສະ ໜອງ : ປ່ຽນແທນປີທີ່ທ່ານໄດ້ສ້າງໂຄງການ.
  • ກະເປົາ : ແທນມັນດ້ວຍຊື່ຂອງຊຸດ.
  • ສິດ ອຳ ນາດ ທຳ ອິດ <[email ປ້ອງກັນ]>, ປີ : ທົດແທນສິ່ງນີ້ດ້ວຍຊື່ຈິງ, ອີເມວຂອງທ່ານແລະປີທີ່ທ່ານແປເອກະສານ.
  • PACKAGE VERSION : ແທນມັນດ້ວຍເວີຊັນຊຸດຈາກແຟ້ມ debian/control.
  • YEAR-MO-DA HO: MI + ZONE : ບໍ່ຕ້ອງການ ຄຳ ອະທິບາຍ, ທ່ານສາມາດປ່ຽນມັນໄດ້ໃນວັນທີທີ່ທ່ານຕ້ອງການ.
  • ຊື່ເຕັມ <> : ຍັງປ່ຽນແທນຊື່ແລະອີເມວຂອງທ່ານ.
  • ທີມງານພາສາ : ທົດແທນມັນດ້ວຍຊື່ຂອງພາສາທີ່ທ່ານ ກຳ ລັງແປເປັນຕົວຢ່າງເຊັ່ນພາສາອາຣັບຫລືພາສາຝຣັ່ງ.
  • ພາສາ : ທີ່ນີ້, ທ່ານຕ້ອງໃສ່ລະຫັດ ISO-639-1 ສຳ ລັບພາສາທີ່ທ່ານ ກຳ ລັງແປ, ຍົກຕົວຢ່າງ, "ar", "fr", "de" ... ອື່ນໆ , ທ່ານສາມາດຊອກຫາບັນຊີລາຍຊື່ທີ່ສົມບູນຢູ່ທີ່ນີ້.
  • CHARSET : ຂັ້ນຕອນນີ້ ສຳ ຄັນ, ທົດແທນສາຍນີ້ໂດຍໃຊ້ "UTF-8" (ໂດຍບໍ່ມີ ຄຳ ເວົ້າ) ເຊິ່ງສະ ໜັບ ສະ ໜູນ ພາສາສ່ວນໃຫຍ່.
  • ດຽວນີ້ເລີ່ມແປແລ້ວ! ຕື່ມການແປພາສາຂອງທ່ານ ສຳ ລັບແຕ່ລະສາຍຫຼັງຈາກ ຄຳ ເວົ້າໃນ " msgstr ". ບັນທຶກເອກະສານແລະອອກ. ເອກະສານແປທີ່ດີ ສຳ ລັບ
    ພາສາອາຫລັບເປັນຕົວຢ່າງຄວນມີລັກສະນະດັ່ງນີ້:

    # 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
    

    ແລະປ່ຽນພາສາລະບົບໂດຍໃຊ້ໂປແກຼມ“ ສະ ໜັບ ສະ ໜູນ ພາສາ ” ຫຼືໃຊ້ໂປແກຼມອື່ນໃດ ໜຶ່ງ ເພື່ອ ພາສາອາຫລັບ (ຫຼືພາສາທີ່ທ່ານໄດ້ແປເອກະສານຂອງທ່ານໃຫ້ເປັນ):

    ຫຼັງຈາກເລືອກ, ໂປແກຼມຂອງທ່ານຈະຖືກແປເປັນພາສາອາຫລັບ.

    ນີ້ສິ້ນສຸດຊຸດຂອງພວກເຮົາກ່ຽວກັບການຂຽນໂປແກຼມ PyGObject ສຳ ລັບ Linux desktop, ແນ່ນອນມັນຍັງມີອີກຫລາຍໆຢ່າງທີ່ທ່ານສາມາດຮຽນຮູ້ຈາກ Python GI API ອ້າງອິງ ..

    ທ່ານຄິດແນວໃດກ່ຽວກັບຊຸດດັ່ງກ່າວ? ທ່ານເຫັນວ່າມັນມີປະໂຫຍດບໍ? ທ່ານສາມາດສ້າງໂປແກຼມ ທຳ ອິດຂອງທ່ານໂດຍປະຕິບັດຕາມຊຸດນີ້ບໍ? ແບ່ງປັນຄວາມຄິດຂອງພວກເຮົາ!