hook_filter_info langcode is always und I am trying to filter text and the result replace depends on the language of the node.
The filter process callback function accepts $langcode argument but it always pass as "und".
If I could access the Entity object to check it's langauge that would be perfect.
I've tried to understand where the "und" value comes from and understand that it's from the field settings.
Currently I'm getting the language code from the active $language object and in order to filter per language I set the filter cache to FALSE and I don't wanna do this.

How can I overcome this problem?

Thanks,
Bnaya
The process callback is generally called from the check_markup() function.

That function blindly passes the $langcode value through to the process function, so it is up to the caller of the check_markup() function to send through the appropriate language.

You can see the list of functions that call check_markup() here.

The main one that you will encounter would be the text module's _text_sanitize() function, which is what formats the text for text fields that user input filters.

As you can see, it also passes through the language of the field.

Going up another level we have hook_field_load(), which also passes through the langcode.

Back again we get field_attach_load(), which calls hook_field_load() via _field_invoke_multiple().

All these are passing through langcode.

field_attach_load() is called by all these functions.

So basically you can scour the API site and see that is calling check_markup() in your case and see why there is no langcode being passed in.

Alternatively, you can install the devel module and put

dpm(debug_backtrace());


in your format process function.

Then load the page where your text is printing out and you will get a backtrace on the screen.

The backtrace will give you all the functions that have been called to get to your code. It shows you all the parameters that have been passed into function along the way.

This way you can more quickly isolate the point where the language becomes LANGUAGE_NONE (UND) - In theory :)