WordPress.org

Ready to get started?Download WordPress

Forums

Transposh WordPress Translation
[resolved] [Plugin: Transposh WordPress Translation] Problem changing images based on language (16 posts)

  1. kiminotsuki
    Member
    Posted 2 years ago #

    Hello, I am translating my site from Japanese into English and would like to change the images in my theme (such as banners) into English as well.

    I have read the topic here...

    http://wordpress.org/support/topic/plugin-transposh-translation-filter-for-wordpress-how-to-change-images-based-on-selected-language?replies=5

    And tried the suggested code...

    image<?php echo $my_transposh_plugin->target_language?>.jpg

    However, there is no effect.

    I also tried to use the shortcode...

    [tp mylang="y" lang="en"]

    Which I found in the FAQ on transposh's website however in this case it breaks the file link all together and the image doesn't load at all in either the original Japanese or the English version of the site.

    Is there any other way to change images based on language, or could anyone possibly give me a simple explanation of how to do this? I'm not an expert at wordpress or php so I might be doing something wrong even after reading all the FAQ.

    Thank you very much for your time.

    http://wordpress.org/extend/plugins/transposh-translation-filter-for-wordpress/

  2. paz2222
    Member
    Posted 2 years ago #

    I'm trying to do the same for posts and pages - having previously installed a PHP execution plugin - but I can't make it work. As the topic kiminotsuki pasted is closed, I'm using this one to find some help...

    Thanks in advance!

  3. kiminotsuki
    Member
    Posted 2 years ago #

    To Paz2222,

    Hi, I still haven't been able to figure out how fix the problem with images in my theme, but I've successfully changed the images in my pages. So, I thought it might work for you too.

    What I did was reupload the images so that they are in the same directory (since wordpress seems to make a new directory for uploaded media each month, if you are uploading with FTP or something just make sure they are in the same folder I think) and then used the shortcode...

    [tp mylang="y" lang="en"]

    before the extension of the file in the img src tag. Such as...

    image[tp mylang="y" lang="en"].jpg

    With the two files "image.jpg" being the original and "imageen.jpg" being the English translated image. Of course change the "en" to whichever language you are translating into.

    This worked for me in pages (I haven't tried in posts because I don't have images in need of translating there), but it doesn't work inside the theme, so I am still stuck there if there is anyone out there who can help.

  4. paz2222
    Member
    Posted 2 years ago #

    Hi kiminotsuki,

    For some reason, I (believe I have) tried following those steps in the past, but it's working now, for pages AND for posts, so thanks a lot for your help :D

    Only place I wasn't able to make it work was on a custom slider (from woothemes), that has an image uploader and I don't have access to the code. I guess I will have to ask them now...

    As for images in themes, I believe it's the php code you have to use, according to what they said in the other topic. Images should be named "image.jpg", "imagees.jpg", "imagede.jpg", etc, just like with the shortcode. But as I haven't tried it, I guess it would be better to wait for someone else's response.

    Thanks and good luck!

  5. kiminotsuki
    Member
    Posted 2 years ago #

    Hi Paz2222,

    I'm glad that it's working for you now :D

    I've tried the php code in the theme's php files the same way as with the shortcode, but it doesn't seem to work. So, I guess I'll have to wait for someone else to respond. Thanks!

  6. Ofer Wald
    Member
    Plugin Author

    Posted 2 years ago #

    Hello @kiminotsuki,

    Inside the theme the shortcode will not work, but you would have to use the code you initially wrote in your first, however you should notice that the $my_transposh_plugin object is a global, so you should gave a line such as
    global $my_transposh_plugin

    Let me know if it worked out for you

  7. kiminotsuki
    Member
    Posted 2 years ago #

    Ofer Wald,

    Hello, thank you very much for your help! This was the problem.
    After I added the global script to all my php files the original code worked perfectly.

    Though I also had to reupload my original files with "ja" at the end of the file names. Since my site's default language is Japanese I added the English translated files with "en" at the end, but I also needed to add "ja" for the Japanese files to load properly. Maybe this is because the original plugin assumes that English is the base language?

    Anyway, it was easily fixed and now everything is working properly for both languages. Thank you very much!

  8. Ofer Wald
    Member
    Plugin Author

    Posted 2 years ago #

    Hi,

    Glad I was able to help

    I don't understand the meaning of the .ja etc, but I guess the plugin does have the assumption of English as the default language in many cases

    :)

  9. jepsiba
    Member
    Posted 2 years ago #

    Hi,
    I'm trying to get the script to work on my theme. I tried all the solutions above, but the images don't load.

    Actually, the images on my theme are hard coded and inside php code.
    ex:

    <?php
    					if(has_post_thumbnail()) {
    							//the_post_thumbnail();?>
    							<img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo get_image_path($post->ID); ?>&h=90&w=255&zc=1" alt="<?php the_title(); ?>">
    						<?php } else {
    							echo '<img src="'.get_bloginfo("template_url").'/images/nothumb.jpg"  alt="No Thumbnail"/>';
    						}?>

    So when I add another php code inside that, it goes nuts. How should I implement it? The image I want to "translate" is nothumb.jpg

    And also:

    After I added the global script to all my php files the original code worked perfectly.

    How exactly do you add the "global" script and what do you mean by "all my php files"?

  10. Ofer Wald
    Member
    Plugin Author

    Posted 2 years ago #

    Hello there,

    From your question I didn't fully understand what you want to achieve, but at least with regard to the global, before regarding the $my_transposh_plugin variable, in a function. one should use:
    global $my_transposh_plugin;

    Good luck
    Ofer.

  11. jepsiba
    Member
    Posted 2 years ago #

    Hello Ofer, thank you for your answer.

    What I would like to do exactly, is add the $my_transposh_plugin variable in this line of code, the image I want to apply it to being nothumb.jpg.

    <?php
    					if(has_post_thumbnail()) {
    							//the_post_thumbnail();?>
    							<img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo get_image_path($post->ID); ?>&h=90&w=255&zc=1" alt="<?php the_title(); ?>">
    						<?php } else {
    							echo '<img src="'.get_bloginfo("template_url").'/images/nothumb.jpg"  alt="No Thumbnail"/>';
    						}?>

    Also, how do you do when the image is called from the css file? In this case, the image is inside an href with a class. The image being bk_readmore.png.

    <a href="<?php the_permalink() ?>" class="readMore">Read More</a>

    #featuredPosts .item .readMore {
    	display:block;
    	width:46px;
    	height:46px;
    	position:absolute;
    	left:370px;
    	top:365px;
    	text-indent:-9999px;
    	background:url(images/bk_readmore.png) 0 -46px no-repeat;

    Thank you

  12. kiminotsuki
    Member
    Posted 2 years ago #

    Hi @jepsiba,

    For the images that are in your theme and embedded in the php code, all you have to do is add this code between the file name and extension, such as...

    nothumb<?php echo $my_transposh_plugin->target_language?>.jpg

    Just put it right in the php code and it should work as long as you have also included the global script in the same php file. Then just upload the translated image in the same location with the language code in the file name. For example if your image was translated into Japanese you should name the file nothumbja.jpg, as "ja" is the language code for Japanese.

    About the images in the css file, I think that I tried this the same way as in the php code but it didn't work for me, so maybe someone else knows the solution.

  13. jepsiba
    Member
    Posted 2 years ago #

    Hello kiminotsuki,

    Thank you for your help.
    Actually, I already tried to add the code between the file name and extension, the thing is, the image is already inside a php line of code, and to insert another php line you have to change the code and I don't know how to do that.

    Also, it is still not clear to me what it means to include the global script in the php file; where should I put it? Where the document starts right before everything else?
    Thank you very much again for your help.

    Jepsiba

  14. kiminotsuki
    Member
    Posted 2 years ago #

    Hi Jepsiba,

    That's strange... my images are also inside php code and it works fine. Unless I'm misunderstanding what you mean by inside the php code...

    For the global script you just have to add this...

    <?php global $my_transposh_plugin?>

    Somewhere in the php file. I don't know if it matters where, but before the images probably. I'm a total amateur so a lot of trial and error was involved in getting my site to work. But maybe after you add the global script it might work?

  15. Ofer Wald
    Member
    Plugin Author

    Posted 2 years ago #

    Hello @Jepsiba

    This is probably the oode you were looking for.

    echo '<img src="'.get_bloginfo("template_url").'/images/nothumb'.$my_transposh_plugin->target_language.'.jpg"  alt="No Thumbnail"/>';

    I think @kininotsuki's answers were really to the point,

    Regarding the .css, you can have a large css file, with multiple options and select the correct class, you can also create a dynamic css file generated from php code, but this is not recommended because of caching and speed issue.

    Good luck

  16. jepsiba
    Member
    Posted 2 years ago #

    Thank you Ofer!
    That's exactly what I was talking about :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic