79
Translate a theme Yoav Farhi @yoavf, [email protected] http://blog.yoavfarhi.com Monday, September 6, 2010

WordPress theme internationalization (i18n)

  • Upload
    yoavf

  • View
    782

  • Download
    4

Embed Size (px)

DESCRIPTION

How to translate a WordPress theme - Creating an rtl.css file for right to left language support - Theme internationalization (i18n) and translation.

Citation preview

Page 1: WordPress theme internationalization (i18n)

Translate a theme

Yoav Farhi

@yoavf, [email protected]://blog.yoavfarhi.com

Monday, September 6, 2010

Page 2: WordPress theme internationalization (i18n)

Prerequisites

To get the most out of this presentation you should be familiar

with the basic structure of a WordPress theme and have a good

grasp of CSS.

Monday, September 6, 2010

Page 3: WordPress theme internationalization (i18n)

?Monday, September 6, 2010

Page 4: WordPress theme internationalization (i18n)

Monday, September 6, 2010

Page 5: WordPress theme internationalization (i18n)

Monday, September 6, 2010

Page 6: WordPress theme internationalization (i18n)

right to lefti18n

Monday, September 6, 2010

Page 7: WordPress theme internationalization (i18n)

right to left

Monday, September 6, 2010

Page 8: WordPress theme internationalization (i18n)

rtl

Monday, September 6, 2010

Page 9: WordPress theme internationalization (i18n)

The ugly way

The right way

Monday, September 6, 2010

Page 10: WordPress theme internationalization (i18n)

Ugly

Directly edit the style.css file

Monday, September 6, 2010

Page 11: WordPress theme internationalization (i18n)

Why ugly?

Monday, September 6, 2010

Page 12: WordPress theme internationalization (i18n)

Why ugly?

No updates

Monday, September 6, 2010

Page 13: WordPress theme internationalization (i18n)

Why ugly?

No updatesCannot redistribute

Monday, September 6, 2010

Page 14: WordPress theme internationalization (i18n)

Why ugly?

No updatesCannot redistribute

Hard with child themes

Monday, September 6, 2010

Page 15: WordPress theme internationalization (i18n)

Right

Create an rtl.css file

Monday, September 6, 2010

Page 16: WordPress theme internationalization (i18n)

rtl.css

Monday, September 6, 2010

Page 17: WordPress theme internationalization (i18n)

rtl.css

Monday, September 6, 2010

Page 18: WordPress theme internationalization (i18n)

rtl.cssThe Basics

Text Alignment

Floats

Positioning

Padding, Margin and Borders

Fonts

Backgrounds

Monday, September 6, 2010

Page 19: WordPress theme internationalization (i18n)

The basics

body { direction:rtl; unicode-bidi:embed; }

Monday, September 6, 2010

Page 20: WordPress theme internationalization (i18n)

The basics

input#url { direction:ltr; }

Monday, September 6, 2010

Page 21: WordPress theme internationalization (i18n)

Monday, September 6, 2010

Page 22: WordPress theme internationalization (i18n)

Text Alignment

#body { text-align: left;}

#body { text-align: right;}

rtl.css

style.css

Monday, September 6, 2010

Page 23: WordPress theme internationalization (i18n)

Monday, September 6, 2010

Page 24: WordPress theme internationalization (i18n)

Positioning

#menu { position: absolute; right: 2px; top: 0;}

#menu {

}

rtl.css

style.css

Monday, September 6, 2010

Page 25: WordPress theme internationalization (i18n)

Positioning

#menu { position: absolute; right: 2px; top: 0;}

#menu {

}

rtl.css

style.css

right: auto; left: 2px;

Monday, September 6, 2010

Page 26: WordPress theme internationalization (i18n)

Monday, September 6, 2010

Page 27: WordPress theme internationalization (i18n)

The Box Model

Diagram CC http://css.flepstudio.org/en/css-box-model/introduction.html

Monday, September 6, 2010

Page 28: WordPress theme internationalization (i18n)

The Box Model

#content { margin: 30px 14em 0 3em; padding-right: 60px; border-right: 1px dashed #000;}

#content {

}

rtl.css

style.css

Monday, September 6, 2010

Page 29: WordPress theme internationalization (i18n)

The Box Model

#content { margin: 30px 14em 0 3em; padding-right: 60px; border-right: 1px dashed #000;}

#content {

}

rtl.css

style.css

margin: 30px 3em 0 14em;

Monday, September 6, 2010

Page 30: WordPress theme internationalization (i18n)

The Box Model

#content { margin: 30px 14em 0 3em; padding-right: 60px; border-right: 1px dashed #000;}

#content {

}

rtl.css

style.css

padding-right: 0; padding-left: 60px;

margin: 30px 3em 0 14em;

Monday, September 6, 2010

Page 31: WordPress theme internationalization (i18n)

The Box Model

#content { margin: 30px 14em 0 3em; padding-right: 60px; border-right: 1px dashed #000;}

#content {

}

rtl.css

style.css

padding-right: 0; padding-left: 60px; border-right: none; border-left: 1px dashed #000;

margin: 30px 3em 0 14em;

Monday, September 6, 2010

Page 32: WordPress theme internationalization (i18n)

Monday, September 6, 2010

Page 33: WordPress theme internationalization (i18n)

Floats

#content h2 { float: right; clear: left;}

#content h2{ float: left; clear: right; }

rtl.css

style.css

Monday, September 6, 2010

Page 34: WordPress theme internationalization (i18n)

Monday, September 6, 2010

Page 35: WordPress theme internationalization (i18n)

Backgrounds

#header a { background: url(grey-s.png) 0 0 no-repeat;}

#header { background-position: 100% 0;

}

rtl.css

style.css

Monday, September 6, 2010

Page 36: WordPress theme internationalization (i18n)

Backgrounds

#header a { background: url(grey-s.png) 0 0 no-repeat;}

#header { background-position: 100% 0;

}

rtl.css

style.css

background-image: url(header-rtl.png);

Monday, September 6, 2010

Page 37: WordPress theme internationalization (i18n)

Backgrounds

#header a{ background: url(header.png) 22px 0 no-repeat;}

#header a{

background-position: ??? 0;}

rtl.css

style.css

Monday, September 6, 2010

Page 38: WordPress theme internationalization (i18n)

Monday, September 6, 2010

Page 39: WordPress theme internationalization (i18n)

Fonts

use basic sans-serif fontsno italics

Monday, September 6, 2010

Page 40: WordPress theme internationalization (i18n)

Fonts

#header, h3, #menu ul li { font: italic 230% Times, serif;}

#header, h3, #menu ul li { font-family: Arial, Helvetica, sans-serif; font-style: normal;}

rtl.css

style.css

Monday, September 6, 2010

Page 41: WordPress theme internationalization (i18n)

Monday, September 6, 2010

Page 42: WordPress theme internationalization (i18n)

Basic classes

rtl.css

style.css .alignleft { float: left;}

Don’t!

Monday, September 6, 2010

Page 43: WordPress theme internationalization (i18n)

Monday, September 6, 2010

Page 44: WordPress theme internationalization (i18n)

Monday, September 6, 2010

Page 45: WordPress theme internationalization (i18n)

right to left

Monday, September 6, 2010

Page 46: WordPress theme internationalization (i18n)

right to lefti18n

Monday, September 6, 2010

Page 47: WordPress theme internationalization (i18n)

i18n ?

Monday, September 6, 2010

Page 48: WordPress theme internationalization (i18n)

internationalization

18

i18n ?

Monday, September 6, 2010

Page 49: WordPress theme internationalization (i18n)

The ugly way

The right way

Monday, September 6, 2010

Page 50: WordPress theme internationalization (i18n)

Ugly

Translate in the template files

Monday, September 6, 2010

Page 51: WordPress theme internationalization (i18n)

Right

Create po/mo translation files

Monday, September 6, 2010

Page 52: WordPress theme internationalization (i18n)

How

Wrap your strings Generate the .POT file

Distribute (and translate)

Monday, September 6, 2010

Page 53: WordPress theme internationalization (i18n)

Wrap your strings

Monday, September 6, 2010

Page 54: WordPress theme internationalization (i18n)

_e( 'text' )__( 'text' )

esc_attr_e( 'text' )_x( 'text' , 'comment' )

_n( '1 comment', ' Lots of comments ', $count )

functions

Monday, September 6, 2010

Page 55: WordPress theme internationalization (i18n)

_e( 'text' ) =

echo the translation

Monday, September 6, 2010

Page 56: WordPress theme internationalization (i18n)

<div class="meta">Filed Under [...]

<div class="meta"><?php _e( "Filed Under", 'mytheme' ); ?>[...]

_e( 'text' )

Monday, September 6, 2010

Page 57: WordPress theme internationalization (i18n)

__( 'text' ) =

pass the translation

Monday, September 6, 2010

Page 58: WordPress theme internationalization (i18n)

<?php the_tags('Tags: '); ?>

<?php the_tags( __('Tags: ', mytheme) ); ?>

__( 'text' )

Monday, September 6, 2010

Page 59: WordPress theme internationalization (i18n)

_e( 'text', 'mytheme' )__( 'text', 'mytheme' )

separates the translation from the core WordPress translation

the textdomain

Monday, September 6, 2010

Page 60: WordPress theme internationalization (i18n)

for more info, check out:wp-includes/l10n.php

Monday, September 6, 2010

Page 61: WordPress theme internationalization (i18n)

Generate the .POT file

Monday, September 6, 2010

Page 63: WordPress theme internationalization (i18n)

2.File -> New Catalog...

Monday, September 6, 2010

Page 64: WordPress theme internationalization (i18n)

3. Enter Project name

Monday, September 6, 2010

Page 65: WordPress theme internationalization (i18n)

4. Paths -> New item -> '. '

Monday, September 6, 2010

Page 66: WordPress theme internationalization (i18n)

5. Keywords -> New item -> '__'

Monday, September 6, 2010

Page 67: WordPress theme internationalization (i18n)

5. New item -> '_e'

Monday, September 6, 2010

Page 68: WordPress theme internationalization (i18n)

6. Save POT in theme dir

Monday, September 6, 2010

Page 69: WordPress theme internationalization (i18n)

7. POEdit will find strings

Monday, September 6, 2010

Page 70: WordPress theme internationalization (i18n)

8. Translate

Monday, September 6, 2010

Page 71: WordPress theme internationalization (i18n)

9. Save as lang_code.po

Monday, September 6, 2010

Page 72: WordPress theme internationalization (i18n)

10. load_theme_textdomain

load_theme_textdomain( 'mytheme', get_template_directory() );functions.php

Monday, September 6, 2010

Page 73: WordPress theme internationalization (i18n)

Monday, September 6, 2010

Page 74: WordPress theme internationalization (i18n)

Almost done

Monday, September 6, 2010

Page 75: WordPress theme internationalization (i18n)

Almost doneRTL Tester plugin

Monday, September 6, 2010

Page 76: WordPress theme internationalization (i18n)

Almost doneRTL Tester plugin

CSS Janus (RTLize your css)

Monday, September 6, 2010

Page 77: WordPress theme internationalization (i18n)

Almost doneRTL Tester plugin

CSS Janus (RTLize your css)

The codex

Monday, September 6, 2010

Page 78: WordPress theme internationalization (i18n)

Almost doneRTL Tester plugin

CSS Janus (RTLize your css)

The codex

Multilingual Plugins

Monday, September 6, 2010

Page 79: WordPress theme internationalization (i18n)

Questions?

@yoavf, [email protected]://blog.yoavfarhi.com

Monday, September 6, 2010