Domaine de texte et fichier language.PO du thème ne fonctionnent pas
-
-
Vérifiez simplement si votreproblèmeest résolu.S'il utilisema solution,veuillez accepterma réponse sima solution a aidé,sinon,faites-lemoi savoirJust 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 réponses
- votes
-
- 2014-03-12
Après avoirinspecté votrethème,voici ce quej'aiproposé. J'aipris la liberté d'inclure également la solution de Rubenpour rendre cette réponse aussi complète quepossible.
Il y aplusieursproblèmesici:
Numéro 1.
load_theme_textdomain( 'transparent', get_template_directory_uri() .'/languages' );
devrait être:
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' );
Lesfichiers de langue doiventtoujours être appelés dans le hook
after_setup_theme
.Aussi
get_template_directory_uri()
devrait être
get_template_directory()
.Numéro 2.
<?php echo __("thanks-for-visiting", 'transparent'); ?>
.esttotalementfaux. Premièrement,n'utilisezjamais
"
dans une chaîne detraduction. Letraducteurne le reconnaîtpaset ignorera cette chaîne. Utiliseztoujours'
. Deuxièmement,neecho
une chaîne avececho
._e
doit être utilisé dans ce cas. Votre chaîne doit donc ressembler à ceci:<?php _e('thanks-for-visiting', 'transparent'); ?>
.Numéro 3. Iln'y apas de domaine detexte défini dans l'en-tête de votrefeuille de style. Ajoutez
Text Domain: transparent
juste au-dessus du*/
defermeture dans votreen-tête. Votreen-tête devrait donc ressembler à ceci:/* 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 */
Numéro 4. La dénomination de votrefichierpoesterronée,ainsi devrait l'être votrefichiermo.
somename-en_US.po
etsomename-en_US.mo
n'est utilisé quepar lesplugins. Lesthèmes utilisent uniquement lesnoms defichiersen_US.po
eten_US.mo
Numéro 5. Votrefichierpoestmal créé. Pour créer unfichierpo avec poedit ,procédez comme suit. Veuilleznoter quemonpoeditesten afrikaans.
Ouvrezpoeditet sélectionnez l'optionpour créer un catalogue. L'écran suivant apparaîtra
.
Remplissez les champs obligatoires commeindiqué.
Cliquezmaintenant sur l'onglet "Chemins des sources"et terminez commeindiqué. Utilisez
.
dans le champ "Paths" si votrefichier de langueest dans le répertoireprincipal,et utilisez..
si lefichier de langueest dans un dossier comme languageCliquezmaintenant sur l'onglet "Mots clés sources"et remplissez commeindiqué.
Enregistrezmaintenant lefichierpoedit sous lenom
en_US.po
dans votrefichier de langues. Ilestimportant que vous sauvegardiez lefichierpo directement à l'emplacement oùil doit setrouver,sinon celane fonctionnerapas. Poedit vamaintenant rechercheret ajoutertoutes les chaînes àtraduire dans votrefichierpo. Unfichiermoest automatiquement créé lorsque lefichierpoestenregistré.À lafin,votreen-têtepo devrait ressembler à ceci
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"
Pourplus d'informations,consultez ce tutoriel. Celam'a vraiment aidé lorsquej'ai commencé lestraductions. J'espère que cela vous aidera.
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.
-
Dansmon cas,c'était lapartieessentielle: _Lesfichiers de langue doiventtoujours être appelés dans le hook after_setup_theme._ J'avais l'habitude de les configurer dans `init`mais celane fonctionneplus.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
N'utilisezpas get_template_directory_uri () .Utilisezplutôt get_template_directory () .Votre code doit ressembler à ceci:
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 ); }
-
Merci @Ruben.J'aifait ce changementmais leproblème demeure.Thanks @Ruben. I made this change but the issue remains.
- 0
- 2014-03-11
- Steve
-
1. Assurez-vous d'ajouter ce code dans unfiltre after_setup_theme. 2. Essayez d'utiliser ceplugin,ilpeutmontrer s'il y a uneerreur avec vosfichiers .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. J'ai ajouté le code ci-dessus dans unefonction appelée `transparent_theme_setup ()`,puis appelé `add_action ('after_setup_theme','transparent_theme_setup');`.C'est ce quetu veux dire?2. Leplugin de codagemontre qu'iln'y apas d'erreur avec lesfichiers .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,c'est correct.@Steve, that is correct.
- 0
- 2014-03-12
- Pieter Goosen
-
D'accord.Ehbien,leproblèmeest resté après quej'aifait cela.Ok. Well, the issue remained after I did that.
- 0
- 2014-03-13
- Steve
-
- 2015-09-03
Lorsque vous utilisez
load_theme_textdomain
,votrenom defichier de langue doit êtrenomméexactementen fonction desparamètres régionaux. Nommez-le en_US.mo au lieu de transparent-en_US.moLisez attentivement lesinstructions à l'adresse: 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
Jene parvienspas àfairefonctionnermestraductions dansmonthème. Voici ce quej'ai
Dansfunctions.php,j'ai:
J'ai
qui contient:
Dans header.php,àpartir de la ligne 58,j'ai:
Dansmon style.css,j'ai ce qui suit
Cependant,sur le frontal ,je vois:
Pouvez-vous voirpourquoi cettetraductionne fonctionnepas?