Dominio di testo del tema e file language.PO non funzionanti
-
-
Bastafareil check-inper vedere seiltuoproblema è stato risolto.Se sta usando lamia soluzione,perfavore accetta lamia risposta se lamia soluzione ha aiutato,in caso contrario,fammelo sapereJust checking in to see if your problem is resolved. If it is using my solution, please accepting my answer if my solution helped, if not, let me know
- 0
- 2014-03-17
- Pieter Goosen
-
3 risposta
- voti
-
- 2014-03-12
Dopo averesaminatoiltuotema,questo è ciò chemi è venutoin mente. Mi sonopreso la libertà diincludere anche la soluzione di Rubenper rendere questa rispostailpiù completapossibile.
Ci sono diversiproblemi qui:
Numero 1.
load_theme_textdomain ('transparent',get_template_directory_uri (). '/languages');
dovrebbeessere:
functiontransparent_theme_setup () { load_theme_textdomain ('transparent',get_template_directory (). '/languages'); $ locale=get_locale (); $ locale_file=get_template_directory (). "/languages/$locale.php"; if (is_readable ($ locale_file)) { require_once ($ locale_file); } } add_action ('after_setup_theme','transparent_theme_setup');
Ifile di lingua devonoessere sempre chiamatinell'hook
after_setup_theme
.Anche
get_template_directory_uri()
dovrebbeessere
get_template_directory ()
.Numero 2.
& lt;?phpecho __ ("grazieper la visita",'trasparente');? >
.ètotalmente sbagliato. Inprimo luogo,non usaremai
"
in una stringa ditraduzione. Iltraduttorenon lo riconoscee salterà quella stringa. Usa sempre'
. In secondo luogo,nonecho
una stringa conecho
._e
dovrebbeessere usatoin questo caso. Quindi latua stringa dovrebbe apparire così:& lt;?php _e ('grazieper la visita','trasparente');? >
.Numero 3. Non è statoimpostato alcun dominio ditestonell'intestazione delfoglio di stile. Aggiungi
Text Domain:transparent
appena soprail*/
di chiusuranell'intestazione. Quindi latuaintestazione dovrebbe assomigliare a questa:/* Nome deltema:trasparente URI deltema: http://websitetechnology.com.au/category/themes/transparent/ Descrizione:tema a due colonne reattivotrasparente. Tag: verde,due colonne,barra laterale destra Autore: Steven Doig URI dell'autore: http://tech.doig.com.au Licenza: GNU General Public License v2 o successiva URI della licenza: http://www.gnu.org/licenses/gpl-2.0.html Versione: 1.2.0 Text Domain:trasparente */ Numero 4. La denominazione delfilepo è sbagliata,così dovrebbeesserloilfilemo.
somename-en_US.po
esomename-en_US.mo
viene utilizzato solo daiplugin. Itemi utilizzano soloi nomi difileen_US.po
een_US.mo
Numero 5. Iltuofilepo è stato creatoin modoerrato. Per creare unfilepo con poedit ,seguii passaggi seguenti. Tienipresente cheilmiotesto èin afrikaans.
Apripoedite seleziona l'opzioneper creare un catalogo. Apparirà la seguente schermata
.
Compilai campi obbligatori comemostrato.
Orafai clic sulla scheda "Percorsi delle sorgenti"e completa comemostrato. Utilizza
.
nel campo "Paths" seilfile dellatua lingua sitrovanella directoryprincipalee utilizza..
seilfile della lingua èin una cartella come languageOrafai clic sulla scheda "Parole chiave delle sorgenti"e compila comemostrato.
Ora salvailfilepoedit come
en_US.po
neltuofile delle lingue. Èimportante salvareilfilepo direttamentenellaposizionein cui deveessere,altrimentinonfunzionerà. Poedit ora cercheràe aggiungeràtutte le stringheper latraduzione altuofilepo. Unfilemo viene creato automaticamente quandoilfilepo viene salvato.Allafine,l'intestazione deltuopo dovrebbe assomigliare a questa
msgstr "" msgstr "" "Versione IDprogetto:trasparente v1.2 \n" "POT-Creation-Date: 2014-03-12 16:25 + 0200 \n" "Data revisione ordine di acquisto: 12/03/2014 16:28 + 0200 \n" "Last-Translator: Pieter Goosen & lt;[email protected]> \n" "Language-Team: Transparent & lt; [email protected]> \n" "Lingua:en \n" "Versione MIME: 1.0 \n" "Content-Type:text/plain; charset=UTF-8 \n" "Content-Transfer-Encoding: 8bit \n" "X-Generator: Poedit 1.5.5 \n" "Elencoparole chiave X-Poedit:gettext;gettext_noop; __; _e; _n: 1,2; _x: 1,2c; _ex: 1,2c \n" "X-Poedit-Basepath:. \ N" "Plural-Forms:nplurals=2;plural=n!=1; \n" "X-Poedit-SourceCharset: UTF-8 \n" "X-Poedit-SearchPath-0: .. \n"
Per ulteriori letture,controlla questo tutorial. Mi ha davvero aiutato quando hoiniziato atradurre. Spero che questo aiuti.
After inspecting your theme, this is what I came up with. I've taken the liberty to include Ruben's solution as well to make this answer as complete as possible.
There are several problems here:
Number 1.
load_theme_textdomain( 'transparent', get_template_directory_uri() .'/languages' );
should be:
function transparent_theme_setup() { load_theme_textdomain( 'transparent', get_template_directory() . '/languages' ); $locale = get_locale(); $locale_file = get_template_directory() . "/languages/$locale.php"; if ( is_readable( $locale_file ) ) { require_once( $locale_file ); } } add_action( 'after_setup_theme', 'transparent_theme_setup' );
Language files must always be called in the
after_setup_theme
hook.Also
get_template_directory_uri()
should be
get_template_directory()
.Number 2.
<?php echo __("thanks-for-visiting", 'transparent'); ?>
.is totally wrong. Firstly, never ever use
"
in a translation string. The translator doesn't recognize it and will skip that string. Always use'
. Secondly, don'techo
a string withecho
._e
should be used in this case. So your string should look like this:<?php _e('thanks-for-visiting', 'transparent'); ?>
.Number 3. There is no text domain set in your stylesheet's header. Add
Text Domain: transparent
just above the closing*/
in your header. So your header should look like this:/* Theme Name: Transparent Theme URI: http://websitetechnology.com.au/category/themes/transparent/ Description: Transparent responsive two-column theme. Tags: green, two-columns, right-sidebar Author:Steven Doig Author URI:http://tech.doig.com.au License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Version:1.2 Text Domain: transparent */
Number 4. The naming for your po file is wrong, so should your mo file be.
somename-en_US.po
andsomename-en_US.mo
is only used by plugins. Themes use only the filenamesen_US.po
anden_US.mo
Number 5. Your po file is wrongly created. To create a po file with poedit, follow the following steps. Please note that my poedit is in Afrikaans.
Open poedit and select the option to create a catalogue. The following screen will appear
.
Fill in the required fields as shown.
Now click "Sources paths" tab and complete as shown. Use
.
in the "Paths" field if your language file is in the main directory, and use..
if the language file is in a folder like languageNow click the "Sources keywords" tab and fill in as shown.
Now save the poedit file as
en_US.po
in your languages file. It is important that you save the po file directly in the location where it must be, otherwise it will not work. Poedit will now search and add all strings for translation to your po file. A mo file is automatically created when the po file is saved.At the end, your po header should look like this
msgid "" msgstr "" "Project-Id-Version: Transparent v1.2\n" "POT-Creation-Date: 2014-03-12 16:25+0200\n" "PO-Revision-Date: 2014-03-12 16:28+0200\n" "Last-Translator: Pieter Goosen <[email protected]>\n" "Language-Team: Transparent <[email protected]>\n" "Language: en\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Poedit 1.5.5\n" "X-Poedit-KeywordsList: gettext;gettext_noop;__;_e;_n:1,2;_x:1,2c;_ex:1,2c\n" "X-Poedit-Basepath: .\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" "X-Poedit-SourceCharset: UTF-8\n" "X-Poedit-SearchPath-0: ..\n"
For further reading, check this tutorial. It really helped me when I started on translations. Hope this helps.
-
Nelmio caso questaera laparteessenziale: _Ifile di lingua devono sempreessere chiamatinell'hook after_setup_theme ._ Li avevoimpostatiin `init`manonfunzionapiù.In my case this was the essential part: _Language files must always be called in the after_setup_theme hook._ I used to set them up in `init` but it doesn't work anymore.
- 0
- 2016-02-17
- Attila Fulop
-
- 2014-03-10
Non utilizzare get_template_directory_uri () .Utilizzainvece get_template_directory () .Iltuo codice dovrebbeessere simile a questo:
load_theme_textdomain( 'transparent', get_template_directory() . '/languages' ); $locale = get_locale(); $locale_file = get_template_directory() . "/languages/$locale.php"; if ( is_readable( $locale_file ) ) { require_once( $locale_file ); }
Don't use get_template_directory_uri(). Use get_template_directory() instead. Your code should look like this:
load_theme_textdomain( 'transparent', get_template_directory() . '/languages' ); $locale = get_locale(); $locale_file = get_template_directory() . "/languages/$locale.php"; if ( is_readable( $locale_file ) ) { require_once( $locale_file ); }
-
Grazie @Ruben.Ho apportato questamodificamailproblema rimane.Thanks @Ruben. I made this change but the issue remains.
- 0
- 2014-03-11
- Steve
-
1. Assicurati di aggiungere quel codice all'interno di unfiltro after_setup_theme. 2. Prova a utilizzare questoplugin,potrebbemostrare se c'è unerrore coni tuoifile .po/.mo: http://wordpress.org/plugins/codestyling-localization/1. Make sure that you add that code inside a after_setup_theme filter. 2. Try using this plugin, it may show if there's an error with your .po/.mo files: http://wordpress.org/plugins/codestyling-localization/
- 1
- 2014-03-11
- Ruben Bristian
-
1. Ho aggiuntoil codice soprain unafunzione chiamata `transparent_theme_setup ()`,quindi ho chiamato `add_action ('after_setup_theme','transparent_theme_setup');`.È ciò cheintendi?2. Ilplugin di codestylingmostra chenon ci sonoerrori coni file .po/.mo.1. I added the code above into a function called `transparent_theme_setup()`, and then called `add_action( 'after_setup_theme', 'transparent_theme_setup' );`. Is this what you mean? 2. Codestyling plugin shows there's no error with .po/.mo files.
- 1
- 2014-03-12
- Steve
-
@ Steve,è corretto.@Steve, that is correct.
- 0
- 2014-03-12
- Pieter Goosen
-
Ok.Bene,ilproblema è rimasto dopo che l'hofatto.Ok. Well, the issue remained after I did that.
- 0
- 2014-03-13
- Steve
-
- 2015-09-03
Quando si utilizza
load_theme_textdomain
ilnome delfile della lingua deveessere denominatoesattamentein base alla locale. Chiamalo en_US.mo invece di transparent-en_US.mo"Leggi attentamente leistruzioni su: https://codex.wordpress.org/Function_Reference/load_theme_textdomain
When using
load_theme_textdomain
your language filename must be named based on the locale exactly. Name it en_US.mo instead of transparent-en_US.moRead the instructions carefully at: https://codex.wordpress.org/Function_Reference/load_theme_textdomain
Non riesco afarfunzionare lemie traduzioninelmiotema. Ecco cosa ho
Infunctions.php,ho:
Sì
che contiene:
In header.php,dalla riga 58 ho:
Nelmio style.css ho quanto segue
Tuttavia,sul front-end ,vedo:
Riesci a capireperché questatraduzionenonfunziona?