Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#21524 closed defect (bug) (invalid)

No translation in ajax file

Reported by: Ninos Ego Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4.1
Component: General Keywords:
Focuses: Cc:


I've got some ajax files in my theme. In that I have included the wp-blog-header.php and written for correct access:

header("HTTP/1.1 200 OK");

All works perfect, also the own defined functions of my theme. But with the translation I've got a problem. My outputs are not translated in the used language. These remain the same. I've used the language functions

_e(), __(), _n(), sprintf()


Think that's a bug..

Change History (8)

comment:1 @SergeyBiryukov3 years ago

  • Keywords reporter-feedback added

Could you provide some code to reproduce the issue?

comment:2 follow-up: @Ninos Ego3 years ago

sure, for example in the TEMPLATE_DIRECTORY/ajax/testfile.php

header("HTTP/1.1 200 OK");

_e('Is it translated?', 'Buddyoffr');


In the .po and .mo file the string is translated, also I get an translated output by copying this line into the function or somewhere else. Only the ajax files put the original string out..

Version 0, edited 3 years ago by Ninos Ego (next)

comment:3 follow-up: @markoheijnen3 years ago

  • Keywords close added

This is not how you want to do things. You should use the WordPress ajax handlers

comment:4 in reply to: ↑ 3 @markoheijnen3 years ago

Replying to markoheijnen:

This is not how you want to do things. You should use the WordPress ajax handlers. See http://codex.wordpress.org/AJAX_in_Plugins

comment:5 @Ninos Ego3 years ago

But why it's not possible in this way, because all other things are working perfectly..Also I think it's a bug, if you want to include wordpress in other boards. Then you have to do this kind of way by including the wp-blog-header.php

comment:6 @markoheijnen3 years ago

  • Keywords reporter-feedback close removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

I tested it and it works. It seems you do something wrong. I did tested it with the default WordPress language file but it should work with custom ones.

Also you should use WordPress AJAX handlers and not like this. Using wp-blog-header.php is in my opinion always wrong.

comment:7 in reply to: ↑ 2 @SergeyBiryukov3 years ago

Replying to Ninos Ego:

sure, for example in the TEMPLATE_DIRECTORY/ajax/testfile.php

My guess is that you're not calling load_theme_textdomain() in that file.

Last edited 3 years ago by SergeyBiryukov (previous) (diff)

comment:8 @Ninos Ego3 years ago

ok works with

load_theme_textdomain( 'PARAMETER', getcwd() . '/../languages' );

Have tried it some days before with no effect, because of a bug. Thanks!

Note: See TracTickets for help on using tickets.