Ready to get started?Download WordPress


[resolved] Ajax Chat won't work with Japanese (20 posts)

  1. chestnut_jp
    Posted 3 years ago #

    The plugin won't accept any Japanese characters.
    All Japanese somehow change to "?".

    User Name for Buddypress cannot be set to 2-byte characters, thus most Japanese use Japanese (2-byte characters) for their nicknames.

    When you set User Name to use Ajax Chat, the user name, which is not Japanese, is shown. However, when you set it to Nickname, which is Japanese (2-byte characters), it becomes only "???".

    At the same time, we cannot chat in Japanese, the plugin anyway seems to accept only one-byte characters. Thus, we have no choice but to chat in English, which is very much inconvenience.

    Does anyone have any idea to fix this problem, for this trouble has long been though I already reported before...

  2. dfa3272008
    Plugin Author

    Posted 3 years ago #

    Any way I can get access to the site and work on it remotely? I don't have a 2-byte setup. I thought I took care of this, but if you're still reporting it then something else must be missing and as you can tell...I didn't test it;)

  3. chestnut_jp
    Posted 3 years ago #

    Thank you for your reply.

    To be honest, I have already used the plugin in Japanese.
    Since it is a kind of rough alternation, I do not think you will implement it.

    However, I will report what I did to use the plugin in Japanese, because it is not a matter of Japanese, but I suppose it is for all people using 2-byte characters.

    Though I said it's rough, it is really simple.

    Just change the type of "userName", "ip", and "text" in tables of ajax_chat_online, ajax_chat_messages, and ajax_chat_bans to VARBINARY. That's it. You can see 2-byte characters like Japanese properly.

    By the way, the plugin's Flex/Ajax bridge (FABridge.js) is out-of-date, and error message of "TypeError: Object #<an HTMLObjectElement> has no method 'create'" is shown when browsing by Google Chrome.

    This is fixed by replacing the file with a new one.

    The new one is available at:

    This must be included in the plugin to be updated.

  4. dfa3272008
    Plugin Author

    Posted 3 years ago #


    I thought utf-8 would suffice. That's what I use. To change variables to varbinary isn't correct I think. There has to be another way. Utf-8 supports it.

    What does your DB_CHARSET variable state in your wp-config.php file? Perhaps I should make the tables match that instead of calling out utf8? Please let me know.


  5. chestnut_jp
    Posted 3 years ago #

    Yes, I use utf-8. Other plugins I use with buddypress are all working properly.

    I alreaday tried various ways, for instance changing the charset from utf-8 to euc or jis, changing variables to other than VARBINARY, and all my trials failed.

    Just one thing I suppose to be a reason is something like what we Japanese see everytime buddypress is upgraded:

    When new BuddyPress is released, we Japanese have to change the line 1031 of bp-activity-templatetags.php as following:

    [ Original ]
    $title = trim( strip_tags( html_entity_decode( utf8_encode( $content[0] ) ) ) );
    [ Changed ]
    $title = trim( strip_tags( html_entity_decode( $content[0] ) ) );

    Otherwise Japanese characters in RSS feeds can not read.

    I first thought that the same thing might happen in the plugin. However, I have not yet found it.

    After changing variables in many ways, only VARBINARY shows Japanese characters right. Thus, I decided to use it. Yes, I know it is not the correct fix.

    I still am searching the best solution.

  6. dfa3272008
    Plugin Author

    Posted 3 years ago #


    At the top of the chat pages what does ? show in lang="?"?

    I think it might be because the language code isn't in chat. If so then the html page doesn't get rendered right.

    See here:
    function getLangCode() {
    // Get the langCode from request or cookie:
    $langCodeCookie = isset($_COOKIE[$this->getConfig('sessionName').'_lang']) ? $_COOKIE[$this->getConfig('sessionName').'_lang'] : null;
    $langCode = $this->getRequestVar('lang') ? $this->getRequestVar('lang') : $langCodeCookie;
    // Check if the langCode is valid:
    if(!in_array($langCode, $this->getConfig('langAvailable'))) {
    // Determine the user language:
    $language = new AJAXChatLanguage($this->getConfig('langAvailable'), $this->getConfig('langDefault'));
    $langCode = $language->getLangCode();
    return $langCode;

    I pass the language from the wp-config file and if it's not one of these then who knows how the page is encoded and hence why varbinary might work.


  7. chestnut_jp
    Posted 3 years ago #

    Thank you for youe continued help.

    First of all, ja.js is lised in the list you showed above.

    Secondly, source of the chat top page reads:
    <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="ja">

    This is written the second line, right after:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    A little bit below, it reads:
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

  8. dfa3272008
    Plugin Author

    Posted 3 years ago #


    For kicks try replacing UTF-8 with SHIFT_JIS in the meta tag.

    You can replace it directly in to the template for now. The template is bp-chat/chat/lib/template/loggedIn.html.

    Also, what does a working Japanese website look like? That would help me.


  9. chestnut_jp
    Posted 3 years ago #

    Changing UTF-8 to SHIFT_JIS or SJIS is not effective. The problem remains.
    I tried in various ways, like once again changing charset of database to SJIS, in vain.

    Since characters in database become ???, I think something somewhere in the plugin scripts change characters code before inserting into database.

    In order to confirm this, I need to know how the plugin handle characters especially right before inserting them into database.

    Could you please the point where characters are converted or processed in the scripts, because the scripts are complicated for me to follow.

  10. dfa3272008
    Plugin Author

    Posted 3 years ago #


    I think I got it. In wp-db.php right after the db makes a connection in the wpdb function you need to add this code:

    mysql_query("SET NAMES 'utf8'");

    This should take care of chat and wordpress for you. Please let me know how you make out.


  11. chestnut_jp
    Posted 3 years ago #

    I added "mysql_query("SET NAMES 'utf8'");" to the line right after "$this->db_connect();" in wp-db.php.

    "$this->db_connect();" is at the line of 480 and is within "function wpdb( $dbuser, $dbpassword, $dbname, $dbhost ).

    In order to see whether this addition solves the problem, I re-create chat tables with the default attributes because I changed attributes to varbinary.

    The result is...
    Sorry, but no change. Japanese words are still restored in the database as ???.

  12. dfa3272008
    Plugin Author

    Posted 3 years ago #


    Hmm, there may be yet another place things are stored without utf8 and set names. You need to call that line out for each mysql connection in order for it to work.

    For kicks did you notice chat groups displayed correctly? I specifically call that out. I'm curious as I want to be sure I'm on the right track here.


  13. chestnut_jp
    Posted 3 years ago #

    Oh I forgot to tell you something.

    First, I changed around the line 246 of /bp-chat/chat/lib/class/CustomAJAXChat.php as following:

    [ Original ]
    if ($row['user_nicename'] == "admin")

    [ Changed ]
    if ($row['user_nicename'] == "xxxxxx")

    Note that xxxxxxx is not the real username. I hide the real username for security reason, because it is Administrator's username.

    I changed "admin" to "xxxxxx" because I created Administrator not as admin but as xxxxxx, and the plugin did not allow xxxxxx to use the command of "/whois" and others that only moderators can use.

    However, when I open the chat page, there is a message of "Admin is offline". Since this does not seem to have any influence on chat itself, I have commented it out not to be displayed.

    So, the answer to your question whether chat groups are disopaly correctly, is "NO".

    I must go to bed as it is already 2:13 am here in Japan.

  14. dfa3272008
    Plugin Author

    Posted 3 years ago #


    Your info is very helpful. I think this will fix the chat ??? issue.

    in bp-chat/chat/lib/class/AJAXChatDataBase.php replace the original function for connect with this:

    // Method to connect to the DataBase server:
    function connect(&$dbConnectionConfig) {
    $this->_connectionID = @mysql_connect(
    if(!$this->_connectionID) {
    $this->_errno = null;
    $this->_error = 'Database connection failed.';
    return false;
    #This handles Russian characters
    mysql_query("SET NAMES 'utf8'");
    return true;


  15. chestnut_jp
    Posted 3 years ago #

    Very strange phenomenon happened.

    First I upgraded the plugin to the latest 1.3.6.
    I re-created database tables with default valiables for verification.

    Before adopting your suggestion, I tried chattgin.
    Wow, Japanese shows correctly, and there are proper Japanese in the database.

    Adopting your suggestion to 1.3.6, on the other hand, results in the fact that null (= empty) in tables.

    For this reason, I will continue using the default 1.3.6 for a while to see if it is really correcting the problem. I will send you Japanese Translation when I confirm it is OK. But, I do not know the way to send it to you.

    Nevertheless, "Admin is offline" is still shown in the chat page, though I changed admin to xxxxxx at the line 246 of /bp-chat/chat/lib/class/CustomAJAXChat.php, in order for me to use commands exclusive to moderators. I do not know how to fix this.

  16. dfa3272008
    Plugin Author

    Posted 3 years ago #


    You lost me a little bit. I'm confused as to what worked for you and what didn't.

    On the dynamicendeavorsllc.com site there's a contact form now and you can send me the translation that way:)


  17. chestnut_jp
    Posted 3 years ago #

    I am confused myself too, because the plugin works fine suddenly!

    Well, I must summarize what I have done.

    First, I found the plugin did not accept any Japanese so I reported it to your site, codewarrior.getpaidfrom.us.

    Then, I myself searched and searched the way to display Japanese, and finally got at the fact that they were shown when variables changed to VARBAINARY in database.

    Though Japanese were actually shown in chatting, there were no sounds and a warning message appeared when using Google Chrome.

    I once again searched the way to fix this, and got at the truth that Flex/Ajax bridge (FABridge.js) was out-of-date, thus I replaced it as I mentioned in previous posts.

    Now that the chat seemed to work fine, except that "Admin is offline" was always displayed, I had been using it until you replied to this topic.

    Your suggestions were tested with the above-mentioned plugin, in which the database tables were changed to VARBINARY and FABridge.js was replaced with the newer one.

    Manwhile, you appeared to update the plugin twice. However, I did not upgrade mine, because I was afraid it would be confusing if I upgraded the plugin while testing.

    And your suggestions were all unsuccessful. So, I decided to try continuing the test with the latest version plugin of 1.3.6.

    I did upgrad the plugin to 1.3.6 from old 1.3.4 or before, and once again returned the database table variables to default ones.
    (Note that I always returned the variables to default values when I tested your suggestions.)

    I tried your suggestion of the change in bp-chat/chat/lib/class/AJAXChatDataBase.php, but it showed nothing and applicable database tables become null (empty) as I reported.

    So, I returned bp-chat/chat/lib/class/AJAXChatDataBase.php to original, and the thing happened. The chatting showed Japanese correctly.

    Your upgrading the plugin to 1.3.5 with new Flex/Ajax bridge (FABridge.js) might have fixed the problem, which I was not sure as I have never tested.

    Now that the plugin works properly, the only problem remains that "Admin is offline" still shows up even after changing "admin" to the correct username in CustomAJAXChat.php. Is this also happening only to Japanese users?

  18. chestnut_jp
    Posted 3 years ago #

    I just sent Japanese Translation and related message via contact form.
    I hope you will accept them.

  19. dfa3272008
    Plugin Author

    Posted 3 years ago #


    Excellent job in the details! I just uploaded the changes now in to 1.3.8. Thank you for your help. I hope everything is going well now.


  20. chestnut_jp
    Posted 3 years ago #

    I have just upgraded to 1.3.8 and have found that the plugin works fine.

    Thus, I marked this post as "resolved", thank you.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic