পিআইজিওজেক্ট অ্যাপ্লিকেশনগুলি বিভিন্ন ভাষায় অনুবাদ করা - পার্ট 5


আমরা আপনার সাথে পাইজিওজেক্ট প্রোগ্রামিং সিরিজটি চালিয়ে যাচ্ছি এবং এই 5 তম অংশে আমরা কীভাবে আমাদের পিজিওজেক্ট অ্যাপ্লিকেশনগুলিকে বিভিন্ন ভাষায় অনুবাদ করতে পারি তা শিখব। আপনার অ্যাপ্লিকেশনগুলি অনুবাদ করা গুরুত্বপূর্ণ যদি আপনি এটি বিশ্বের জন্য প্রকাশ করতে চলেছেন তবে শেষ ব্যবহারকারীদের পক্ষে এটি আরও বেশি ব্যবহারকারী বান্ধব হবে কারণ প্রত্যেকেই ইংরেজি বোঝে না।

অনুবাদ প্রক্রিয়া কীভাবে কাজ করে

আমরা এই পদক্ষেপগুলি ব্যবহার করে লিনাক্স ডেস্কটপের অধীনে কোনও প্রোগ্রাম অনুবাদ করার পদক্ষেপগুলি সংক্ষেপ করতে পারি:

  1. পাইথন ফাইল থেকে অনুবাদযোগ্য স্ট্রিংগুলি বের করুন
  2. স্ট্রিংগুলিকে একটি । পট ফাইলে সংরক্ষণ করুন যা ফর্ম্যাট যা আপনাকে এটি পরে অন্য ভাষায় অনুবাদ করতে দেয়
  3. স্ট্রিংগুলির অনুবাদ শুরু করুন
  4. নতুন অনুবাদকৃত স্ট্রিংগুলিকে একটি পিও ফাইলে রফতানি করুন যা সিস্টেমের ভাষা পরিবর্তিত হলে স্বয়ংক্রিয়ভাবে ব্যবহৃত হবে
  5. মূল পাইথন ফাইল এবং .ডেস্কটপ ফাইলে কিছু ছোট প্রোগ্রামযুক্ত পরিবর্তন যুক্ত করুন

এবং এটাই! এই পদক্ষেপগুলি করার পরে আপনার অ্যাপ্লিকেশনটি বিশ্বজুড়ে সমস্ত ব্যবহারকারীদের জন্য ব্যবহারের জন্য প্রস্তুত হয়ে উঠবে (হবে .. আপনার প্রোগ্রামটি বিশ্বের সমস্ত ভাষায় অনুবাদ করতে হবে, যদিও!), সাউন্ড কী সহজ হয় না? :-)

প্রথমে কিছুটা সময় বাঁচাতে নীচের লিঙ্ক থেকে প্রজেক্ট ফাইলগুলি ডাউনলোড করুন এবং আপনার হোম ডিরেক্টরিতে ফাইলটি বের করুন।

  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.

এছাড়াও “ মাইপোগ্রাম ” ফাইলটি খুলুন এবং আমরা যে প্রোগ্রামিক পরিবর্তনগুলি করেছি তা দেখুন, সমস্ত পরিবর্তনগুলি মন্তব্যে ব্যাখ্যা করা হয়েছে:

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

এখন .. আসুন আমাদের প্রোগ্রামটির অনুবাদ শুরু করি। প্রথমে । পট ফাইলটি তৈরি করুন (প্রোগ্রামে সমস্ত অনুবাদযোগ্য স্ট্রিং রয়েছে এমন একটি ফাইল) যাতে আপনি
নিম্নলিখিত কমান্ড ব্যবহার করে অনুবাদ শুরু করতে পারেন:

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

এটি নীচের কোডটি সহ মূল প্রকল্প ফোল্ডারের " পো " ফোল্ডারের ভিতরে " মাইপোগ্রাম.পট " ফাইল তৈরি করতে চলেছে:

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

এখন স্ট্রিংগুলির অনুবাদ শুরু করার জন্য .. " আইএসও -9৩৯-১৯" ভাষা কোডের ভিতরে ভাষা কোডগুলি ব্যবহার করে আপনি আপনার প্রোগ্রামটি অনুবাদ করতে চান এমন প্রতিটি ভাষার জন্য একটি পৃথক ফাইল তৈরি করুন "ফোল্ডার, উদাহরণস্বরূপ, আপনি যদি আপনার প্রোগ্রামটি আরবি তে অনুবাদ করতে চান তবে" আর.পি "নামে একটি ফাইল তৈরি করুন এবং" এটিতে মাইপোগ্রাম.পট ফাইল করুন।

আপনি যদি আপনার প্রোগ্রামটি জার্মান তে অনুবাদ করতে চান তবে একটি " ডিপো " ফাইল তৈরি করুন এবং " মাইপোগ্রাম.পট " থেকে সামগ্রীগুলি অনুলিপি করুন এটিতে ফাইল করুন .. এবং সুতরাং একটি, আপনাকে অবশ্যই প্রতিটি ভাষার জন্য একটি ফাইল তৈরি করতে হবে যাতে আপনি নিজের প্রোগ্রামটি অনুবাদ করতে চান।

এখন, আমরা “ আর.পি ” ফাইলটিতে কাজ করব, “ মাইপোগ্রাম.পট ” ফাইল থেকে বিষয়বস্তু অনুলিপি করব এবং সেই ফাইলের ভিতরে রেখে নীচেরটিকে সম্পাদনা করব :

  1. কিছু বর্ণনামূলক শিরোনাম : আপনি চাইলে এখানে আপনার প্রকল্পের শিরোনাম প্রবেশ করতে পারেন
  2. বছর প্যাকেজের কপিরাইট হোল্ডার : আপনি যে বছর প্রকল্পটি তৈরি করেছেন তা এটির সাথে প্রতিস্থাপন করুন
  3. প্যাকেজ : এটি প্যাকেজের নামের সাথে প্রতিস্থাপন করুন
  4. প্রথম লেখক <[ইমেল সুরক্ষিত]>, ইয়ার : এটি আপনার আসল নাম, ইমেল এবং যে বছর আপনি ফাইলটি অনুবাদ করেছেন তার সাথে এটি প্রতিস্থাপন করুন
  5. প্যাকেজ সংস্করণ : এটি ডেবিয়ান/নিয়ন্ত্রণ ফাইল থেকে প্যাকেজ সংস্করণে প্রতিস্থাপন করুন
  6. YEAR-MO-DA HO: MI + ZONE : এর ব্যাখ্যা দরকার নেই, আপনি এটি যে কোনও তারিখে চান তা পরিবর্তন করতে পারেন
  7. সম্পূর্ণ নাম <[ইমেল সুরক্ষিত]> : এটিকে আপনার নাম এবং ইমেল প্রতিস্থাপন করুন
  8. ভাষা-দল : আপনি যে ভাষায় অনুবাদ করছেন তার নামের সাথে এটি প্রতিস্থাপন করুন, উদাহরণস্বরূপ "আরবি" বা "ফরাসি"
  9. ভাষা : এখানে, আপনি যে ভাষায় অনুবাদ করছেন সেটির জন্য আপনাকে অবশ্যই ISO-639-1 কোডটি sertোকাতে হবে, উদাহরণস্বরূপ "আর", "ফ্র", "ডি" ইত্যাদি .. , আপনি এখানে একটি সম্পূর্ণ তালিকা খুঁজে পেতে পারেন
  10. চারসেট : এই পদক্ষেপটি গুরুত্বপূর্ণ, এই স্ট্রিংটিকে "ইউটিএফ -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

এবং " ভাষা সমর্থন " প্রোগ্রামটি ব্যবহার করে বা আরবি (বা আপনি যে ভাষাতে আপনার ফাইলটি অনুবাদ করেছেন সেই ভাষায়) কোনও সিস্টেম ব্যবহার করে সিস্টেমের ভাষা পরিবর্তন করুন:

নির্বাচনের পরে, আপনার প্রোগ্রামটি আরবি ভাষায় অনুবাদ করা হবে।

এখানে লিনাক্স ডেস্কটপের জন্য পাইজিওজেক্ট প্রোগ্রামিং সম্পর্কে আমাদের সিরিজটি শেষ হয়, অবশ্যই পাইথন জিআই এপিআই রেফারেন্স থেকে আপনি আরও অনেক কিছু শিখতে পারেন ..

সিরিজটি সম্পর্কে আপনার কী ধারণা? আপনি এটি দরকারী মনে হয়? আপনি কি এই সিরিজটি অনুসরণ করে আপনার প্রথম অ্যাপ্লিকেশন তৈরি করতে সক্ষম হয়েছিলেন? আমাদের আপনার মতামত শেয়ার করুন!