- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 1 and 9 items
- Europe
- Exclusive Author
- Has been a member for 2-3 years
- Item was Featured
- Referred between 100 and 199 users
The code i have ( until now ) is something like so:
//GENEARAL
define('dt_ReadMore','Read More »');
define('dt_Permalink','Permalink to ');
instead of the texts i will have variables that will get the values from metaboxes in the admin panel so i will have strings, not texts. How can i make them translatable. I cannot find any good ideas at the moment and would appreciate any help. 
- Sold between 250 000 and 1 000 000 dollars
- Community Moderator
- Author was Featured
- Item was Featured
- Bought between 50 and 99 items
- Referred between 1000 and 1999 users
- Has been a member for 3-4 years
- Repeatedly Helped protect Envato Marketplaces against copyright violations
Have you utilized WordPress’ standard i18n techniques?
http://codex.wordpress.org/I18n_for_WordPress_Developers http://codex.wordpress.org/Translating_WordPressCan’t tell if this is what you’re looking for or if you’re trying to do something beyond these functions 
- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 1 and 9 items
- Europe
- Exclusive Author
- Has been a member for 2-3 years
- Item was Featured
- Referred between 100 and 199 users
__($dt_ReadMore,'duotive');because the scanner will not know what to do there and will just add the variable as normal text. The end point i want to make strings translatable from the backend but also with the po and mo files because some users may want to use multi language.
- Author had a File in an Envato Bundle
- Sold between 250 000 and 1 000 000 dollars
- Author was Featured
- Item was Featured
- Contributed a Tutorial to a Tuts+ Site
- Exclusive Author
- Has been a member for 3-4 years
- India
Just tested the following on a test theme and I got the output successfully:
<?php define('dt_ReadMore',__('Read More »', 'duotive'));
echo dt_ReadMore; ?>
Now since the constant is still accepting the value and echoing correctly, I hope the gettext will parse __() too.
- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 1 and 9 items
- Europe
- Exclusive Author
- Has been a member for 2-3 years
- Item was Featured
- Referred between 100 and 199 users
Now see that is the problem? I want instead of the text to have a php string that i get from the backend.
- Sold between 250 000 and 1 000 000 dollars
- Community Moderator
- Author was Featured
- Item was Featured
- Bought between 50 and 99 items
- Referred between 1000 and 1999 users
- Has been a member for 3-4 years
- Repeatedly Helped protect Envato Marketplaces against copyright violations
I guess I’m probably missing something, but I thought the issue was just that if $dt_ReadMore doesn’t have a translation, it’ll just spit back out the value of $dt_ReadMore. So couldn’t you do something like this?
//Define default
define( 'dt_ReadMore', 'Read More »' );
//Retrive special value from DB (with 'dt_ReadMore' key), or set to default
$dt_ReadMoreText = get_option('dt_ReadMore', dt_ReadMore);
$readMoreText = __($dt_ReadMoreText, 'duotive');
Of course, this code could be condensed, or made into a function of its own. But at this point I think we have the following result:
1. If no translation exists, and no ‘special value’ is set, the default is returned.
2. If a translation exists, and no ‘special value’ is set, the translation is returned.
3. If a ‘special value’ is set, it is returned (unless there is a translation for the special value)
I think that would allow users to change individual words but still make use of translations?
- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 1 and 9 items
- Europe
- Exclusive Author
- Has been a member for 2-3 years
- Item was Featured
- Referred between 100 and 199 users
Yes this is true, excerpt for the 3rd conclusion, witch in my opinion cannot be true, because when scanning with POEdit you cannot have the strings from the database. This was one of my options, if onone has any better ideas i will go with this. Thanks man
- Attended a Community Meetup
- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 1 and 9 items
- Contributed a Tutorial to a Tuts+ Site
- Exclusive Author
- Has been a member for 4-5 years
- Item was Featured
I’ve always used this:
$myString = sprintf ( __('Use %s to include the text.', THEME_NAME), $theTerm );
echo $myString;
When translating they must keep the “%s” in the translation but it works. If I remember correctly, POEdit recognizes strings with “%s” and knows they’re special, but I could be mixing that up with something else.
- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 1 and 9 items
- Europe
- Exclusive Author
- Has been a member for 2-3 years
- Item was Featured
- Referred between 100 and 199 users
Parallelus saidThanks
I’ve always used this:$myString = sprintf ( __('Use %s to include the text.', THEME_NAME), $theTerm ); echo $myString;When translating they must keep the “%s” in the translation but it works. If I remember correctly, POEdit recognizes strings with “%s” and knows they’re special, but I could be mixing that up with something else.
so this is tested and it works.. good
. Please correct me if i am wrong:
define( 'dt_ReadMore', sprintf ( __('Read More »', 'duotive'), get_option('dt_ReadMore') ) );
I do not know regex and sprintf functions 
- Sold between 250 000 and 1 000 000 dollars
- Community Moderator
- Author was Featured
- Item was Featured
- Bought between 50 and 99 items
- Referred between 1000 and 1999 users
- Has been a member for 3-4 years
- Repeatedly Helped protect Envato Marketplaces against copyright violations
duotive said
Parallelus saidThanks
I’ve always used this:$myString = sprintf ( __('Use %s to include the text.', THEME_NAME), $theTerm ); echo $myString;When translating they must keep the “%s” in the translation but it works. If I remember correctly, POEdit recognizes strings with “%s” and knows they’re special, but I could be mixing that up with something else.so this is tested and it works.. good
. Please correct me if i am wrong:
define( 'dt_ReadMore', sprintf ( __('Read More »', 'duotive'), get_option('dt_ReadMore') ) );I do not know regex and sprintf functions![]()
sprintf is a formatter – basically it replaces variables in a preformatted string. So without a %s or %d or the like in the first argument, I don’t think it’s doing anything.
See http://php.net/manual/en/function.sprintf.php
I was going to suggest this earlier, but I think the problem I think is that you’re not replacing part of a string, but the whole thing. I think the sprintf i18n method is intended to be used when a string needs to be translated, but a part of that string varies, for example, a number. It basically allows you to translate a string, then replace the variable. In your case, the entire string is a variable, so I don’t think this does anything for you (you need to pass something to the translation function).
