Make WordPress Core

Opened 21 months ago

Closed 21 months ago

Last modified 21 months 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 SergeyBiryukov21 months ago

  • Keywords reporter-feedback added

Could you provide some code to reproduce the issue?

comment:2 follow-up: Ninos Ego21 months ago

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

header("HTTP/1.1 200 OK");

_e('Translate!', 'PARAMETER');

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..

Last edited 21 months ago by Ninos Ego (previous) (diff)

comment:3 follow-up: markoheijnen21 months 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 markoheijnen21 months 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 Ego21 months 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 markoheijnen21 months 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 SergeyBiryukov21 months 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 than file.

Version 0, edited 21 months ago by SergeyBiryukov (next)

comment:8 Ninos Ego21 months 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.