<\/a><\/figure>\n\n\n\n\u00dapln\u011b dole pak vid\u00edte po\u010det \u0159et\u011bzc\u016f, i to kolik jich je nep\u0159elo\u017een\u00fdch.<\/p>\n\n\n\n
Po p\u0159elo\u017een\u00ed v\u0161ech \u0159et\u011bzc\u016f se bude \u0161ablona zobrazovat kompletn\u011b v \u010de\u0161tin\u011b. Pokud se v\u00e1m n\u011bkter\u00e9 \u010d\u00e1sti nep\u0159elo\u017e\u00ed, je to proto\u017ee nejsou pou\u017eity funkce pro p\u0159eklad. Budete muset soubory \u0161ablony otev\u0159\u00edt v editoru a anglick\u00e9 \u010d\u00e1sti p\u0159elo\u017eit tam. Jak zjistit, zda je text p\u0159ipraven k p\u0159ekladu si uk\u00e1\u017eeme d\u00e1le.<\/p>\n\n\n\n
Textdomain<\/h3>\n\n\n\n
Pro nedostatek p\u0159edstavivosti pro p\u0159eklad, naz\u00fdv\u00e1m textdomain, prost\u011b jazykovou dom\u00e9nou. Jedn\u00e1 se o definici dom\u00e9ny, do kter\u00e9 budou nahr\u00e1ny v\u0161echny p\u0159elo\u017een\u00e9 \u0159et\u011bzce z mo souboru, pro aktu\u00e1ln\u00ed jazyk. V na\u0161em p\u0159\u00edpad\u011b tedy cs_CZ.mo.<\/p>\n\n\n\n
Definice jazykov\u00e9 dom\u00e9ny:<\/p>\n\n\n\n
add_action('after_setup_theme', 'my_theme_setup');\nfunction my_theme_setup(){\n load_theme_textdomain('simple', get_template_directory() . '\/languages');\n}\n<\/pre>\n\n\n\nTuto funkci vlo\u017ete do functions.php a pomoc\u00ed load_theme_textdomain() jste vytvo\u0159ili jazykovou dom\u00e9nu ‚simple‘ a definovali cestu ke slo\u017ece s p\u0159eklady.<\/p>\n\n\n\n
Funkce pro p\u0159eklad \u0159et\u011bzc\u016f<\/h3>\n\n\n\n
Titulek nen\u00ed zcela p\u0159esn\u00fd, proto\u017ee samotn\u00e9 tyto funkce \u0159et\u011bzce nep\u0159ekl\u00e1daj\u00ed, pouze je p\u0159id\u00e1vaj\u00ed do seznamu fr\u00e1z\u00ed k p\u0159ekladu. Celkem se jedn\u00e1 o 4 funkce<\/p>\n\n\n\n
Funkce __()<\/h3>\n\n\n\n
Tato funkce vrac\u00ed p\u0159elo\u017een\u00fd \u0159et\u011bzec, pokud p\u0159eklad existuje.
Pou\u017eit\u00ed:<\/p>\n\n\n\n
$nadpis = '<\/pre>\n\n\n\n‚.__(‚Nothing found‘,’simple‘).‘<\/h2>\n\n\n\n';\necho $nadpis;\n<\/pre>\n\n\n\nUvnit\u0159 funkce je nejprve \u0159et\u011bzec, kter\u00fd chceme nahradit p\u0159elo\u017een\u00fdm a n\u00e1sleduje jazykov\u00e1 dom\u00e9na.
D\u016fle\u017eit\u00e9 u t\u00e9to funkce je, \u017ee vrac\u00ed \u0159et\u011bzec jako prom\u011bnnou, pokud tedy nap\u00ed\u0161ete:<\/p>\n\n\n\n
__(‚Nothing found‘,’simple‘)<\/h2>\n\n\n\n
nebude to fungovat.<\/p>\n\n\n\n
Z p\u0159\u00edkladu je tak\u00e9 vid\u011bt, jak ur\u010dit \u010d\u00e1sti \u0161ablony, kter\u00e9 nejsou p\u0159ipraveny k p\u0159elo\u017een\u00ed:<\/p>\n\n\n\n
Nothing found<\/h2>\n\n\n\n
Toto budete bohu\u017eel muset p\u0159elo\u017eit ru\u010dn\u011b.<\/p>\n\n\n\n
Funkce _e()<\/h3>\n\n\n\n
Dal\u0161\u00ed funkce, kter\u00e1 vrac\u00ed p\u0159elo\u017een\u00e9 \u0159et\u011bzce. Rozd\u00edl je v tom, \u017ee tato je rovnou vyp\u00ed\u0161e.
P\u0159\u00edklad:<\/p>\n\n\n\n
<\/h1>\n\n\n\n<\/pre>\n\n\n\nM\u00e1m vyzkou\u0161eno, \u017ee _e() nelze pou\u017e\u00edt uvnit\u0159 jin\u00fdch funkc\u00ed, toto v\u00e1m nebude fungovat:<\/p>\n\n\n\n
edit_comment_link(_e('(Edit)','simple'),' ','')<\/pre>\n\n\n\nFunkce _n()<\/h3>\n\n\n\n
Tato funkce vrac\u00ed jednotn\u00e9, nebo mno\u017en\u00e9 \u010d\u00edslo podle zadan\u00e9 prom\u011bnn\u00e9.<\/p>\n\n\n\n
Zde p\u0159\u00edklad bude za tis\u00edc slov:<\/p>\n\n\n\n
$rating = '3';\n$text = sprintf( _n( '1 star', '%s stars', $rating, 'simple' ), $rating );\necho $text;\n<\/pre>\n\n\n\n$rating je \u010d\u00edseln\u00e1 hodnota, 1 star je varianta pro jednotn\u00e9 \u010d\u00edslo, %s stars je varianta pro mno\u017en\u00e9 \u010d\u00edslo a simple je jazykov\u00e1 dom\u00e9na.
D\u00edky tomu m\u016f\u017eete definovat p\u0159eklad i pro r\u016fzn\u00e9 varianty textu, jako je nap\u0159\u00edklad „1 koment\u00e1\u0159, 5 koment\u00e1\u0159\u016f“ a podobn\u011b.<\/p>\n\n\n\n
Funkce _x()<\/h3>\n\n\n\n
Posledn\u00ed funkc\u00ed d\u016fle\u017eitou pro p\u0159eklad, ale pom\u011brn\u011b m\u00e9n\u011b vyu\u017e\u00edvanou, je _x(). V p\u0159\u00edpad\u011b, \u017ee m\u00e1te jedno slovo, nebo fr\u00e1zi, kterou m\u016f\u017eete ve stejn\u00e9m zn\u011bn\u00ed pou\u017e\u00edt v r\u016fzn\u00fdch p\u0159\u00edpadech – kontextech, sta\u010d\u00ed definovat jeden \u0159et\u011bzec a k n\u011bmu definovat kontexty, p\u0159i kter\u00fd se bude pou\u017e\u00edvat.<\/p>\n\n\n\n
P\u0159\u00edklad:<\/p>\n\n\n\n
echo 'N\u00e1\u0161 prvn\u00ed '._x( 'pokus', 'prvn\u00ed', 'simple' );\necho 'N\u00e1\u0161 druh\u00fd '._x( 'pokus', 'druh\u00fd', 'simple' );\n<\/pre>\n\n\n\nDal\u0161\u00ed funkce pou\u017e\u00edvan\u00e9 pro p\u0159eklad<\/h3>\n\n\n\n
Pro \u00faplnost zde uvedu i dal\u0161\u00ed funkce, kter\u00e9 se pro v\u00fdpis p\u0159elo\u017een\u00fdch \u0159et\u011bzc\u016f pou\u017e\u00edvaj\u00ed:<\/p>\n\n\n\n
_ex()<\/strong>, _nx()<\/strong>, esc_attr__()<\/strong>, esc_attr_e()<\/strong>, esc_attr_x()<\/strong>, esc_html__()<\/strong>, esc_html_e()<\/strong>, esc_html_x()<\/strong>, _n_noop()<\/strong>, _nx_noop()<\/strong>, translate_nooped_plural()<\/strong><\/p>\n\n\n\nTyto funkce budou ur\u010dit\u011b obsahem jednoho z dal\u0161\u00edch \u010dl\u00e1nk\u016f.<\/p>\n","protected":false},"excerpt":{"rendered":"
Jedna z nej\u010dast\u011bj\u0161\u00edch ot\u00e1zek na diskuz\u00edch je, jak m\u00e1m p\u0159elo\u017eit \u0161ablonu nebo plugin. Titulek dne\u0161n\u00edho \u010dl\u00e1nku je trochu zav\u00e1d\u011bj\u00edc\u00ed, proto\u017ee mi si uk\u00e1\u017eeme nejen, jak takovou \u0161ablonu p\u0159elo\u017eit, ale i jak \u0161ablonu, kterou vytv\u00e1\u0159\u00edte, p\u0159ipravit pro p\u0159eklady. Tak\u017ee nejprve, jak p\u0159elo\u017eit \u0161ablonu, nebo plugin. <\/p>\n","protected":false},"author":1,"featured_media":8618,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,30],"tags":[301],"class_list":["post-903","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-navody","category-wordpress","tag-preklad-sablony-wordpress"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/903"}],"collection":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/comments?post=903"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/903\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/8618"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}