Your SlideShare is downloading. ×
0
MULTI-LANGUAGE FOR PHP
WITH GETTEXT
Binh Quan
2014-05-20
Table of content
1. Why Gettext?
2. Applying to a PHP project
3. Converting text
4. Multi-language for images & a static p...
1. Why Gettext
• Encode and compress messages in binary
format
• Support by almost popular programming
languages (C, C++, ...
2. Applying to a PHP project
• Put the code below into entry PHP script
require_once("locale/bootstrap.php");
• Edit confi...
3. Converting text
• Text in PHP scripts
<?php
$msg = _t(“This is a message for translation”);
echo $msg;
• Text in HTML f...
4. Multi-language for images & static
pages
• With images
<img src=“/path/to/image/<?php echo _t(“banner.png”);?>”/>
• Wit...
5. Multi-language for Javascript files
(Pending)
7
6. Translating with parameters
<?php
$msg = _t(“This photo has {comments} {commentText}”, array(
“{comments}” => $totalCom...
7. Group translations by domain
To enable domain translation, do following steps:
1. Define domain translation function in...
8. Multi-language for Guess & Logged
Users
• This library using cookie for keeping user’s preferred
language
• Already ena...
9. Using POEdit
• Preparing your .po file
• Setting source paths & keywords
• Extracting messages
• Perform translation
• ...
QUESTION?
12
Upcoming SlideShare
Loading in...5
×

Multi language for php with gettext

952

Published on

A short presentation on how to integrate small library for supporting multi-language in a PHP project

Published in: Software, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
952
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • This template can be used as a starter file for presenting training materials in a group setting.SectionsRight-click on a slide to add sections. Sections can help to organize your slides or facilitate collaboration between multiple authors.NotesUse the Notes section for delivery notes or to provide additional details for the audience. View these notes in Presentation View during your presentation. Keep in mind the font size (important for accessibility, visibility, videotaping, and online production)Coordinated colors Pay particular attention to the graphs, charts, and text boxes.Consider that attendees will print in black and white or grayscale. Run a test print to make sure your colors work when printed in pure black and white and grayscale.Graphics, tables, and graphsKeep it simple: If possible, use consistent, non-distracting styles and colors.Label all graphs and tables.
  • Give a brief overview of the presentation. Describe the major focus of the presentation and why it is important.Introduce each of the major topics.To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.
  • Transcript of "Multi language for php with gettext"

    1. 1. MULTI-LANGUAGE FOR PHP WITH GETTEXT Binh Quan 2014-05-20
    2. 2. Table of content 1. Why Gettext? 2. Applying to a PHP project 3. Converting text 4. Multi-language for images & a static page 5. Multi-language for Javascript files 6. Translating with parameters 7. Group translations by domain 8. Multi-language for Guess & Logged Users 9. Using POEdit 2
    3. 3. 1. Why Gettext • Encode and compress messages in binary format • Support by almost popular programming languages (C, C++, Java, Python, Objective C, C#, etc) • Support translating text in Singular/Plural form • Powerful tool: POEdit 3
    4. 4. 2. Applying to a PHP project • Put the code below into entry PHP script require_once("locale/bootstrap.php"); • Edit config.php to match your need • Translated message files are laid at: locale/{langcode}/LC_MESSAGES/{domain}.po 4
    5. 5. 3. Converting text • Text in PHP scripts <?php $msg = _t(“This is a message for translation”); echo $msg; • Text in HTML files <p> <span><?php echo _t(“This is a span text”);?></span> </p> 5
    6. 6. 4. Multi-language for images & static pages • With images <img src=“/path/to/image/<?php echo _t(“banner.png”);?>”/> • With static pages <h2><?php echo _t(“My CMS Page”);?></h2> <?php include(_t(“cms_page.phtml”));?> 6
    7. 7. 5. Multi-language for Javascript files (Pending) 7
    8. 8. 6. Translating with parameters <?php $msg = _t(“This photo has {comments} {commentText}”, array( “{comments}” => $totalComments, “{commentText} => _p(“comment", “comments", $totalComments) )); echo $msg; If $totalComments = 5, this will output: This photo has 5 comments 8
    9. 9. 7. Group translations by domain To enable domain translation, do following steps: 1. Define domain translation function in function.php 2. Create translation file and enable function name as keyword for extracting text 3. Use POEdit for extracting text 9
    10. 10. 8. Multi-language for Guess & Logged Users • This library using cookie for keeping user’s preferred language • Already enabled for Guess • Enabling multi-language for logged users by adding following script after bootstrap.php is loaded <?php require_once("locale/bootstrap.php"); // some code for getting user’s language code putenv("LANGUAGE={$userLangCode}"); 10
    11. 11. 9. Using POEdit • Preparing your .po file • Setting source paths & keywords • Extracting messages • Perform translation • Update changes 11
    12. 12. QUESTION? 12
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×