Raised This Month: $32 Target: $400
 8% 

Solved Formatting in translations


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 06-18-2017 , 08:03   Formatting in translations
Reply With Quote #1

Hello,
This is my code:
Code:
CPrintToChat(client, "%s %t", prefix, "Respawns left", client, RespawnLeft[client]);
And this is the translation:
Code:
	"Respawns left"
	{
		"#format"	"{1:d}"
		"en"	"You have {1} respawns left!"
		"se"	"Du har {1} respawns kvar!"
	}
The value of RespawnLeft[client] is 3, but it prints 1. How come? Did I do something wrong?
__________________

Last edited by condolent; 06-21-2017 at 07:50.
condolent is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 06-18-2017 , 08:14   Re: Formatting in translations
Reply With Quote #2

Have you tried ?
PHP Code:
CSetPrefix("MyPrefix"); 
Btw. isn't there a difference between %t and %T ?
- Yes, use %T
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.

Last edited by KissLick; 06-18-2017 at 08:15.
KissLick is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 06-18-2017 , 08:21   Re: Formatting in translations
Reply With Quote #3

you can do

PHP Code:
#define prefix [PreFix]
CPrintToChat(client"%t""Respawns left"prefixRespawnLeft[client]); 
Code:
"Respawns left"
	{
		"#format"	"{1:s},{1:d}"
		"en"	"{1} You have {2} respawns left!"
		"se"	"{1} Du har {2} respawns kvar!"
	}
and your question bout why its printing 1 is because in your code you are passing the client index
Quote:
CPrintToChat(client, "%s %t", prefix, "Respawns left", client, RespawnLeft[client]);

Last edited by 8guawong; 06-18-2017 at 08:24.
8guawong is offline
CamerDisco
AlliedModders Donor
Join Date: Aug 2015
Location: Poland
Old 06-18-2017 , 08:24   Re: Formatting in translations
Reply With Quote #4

Format translate like this:
PHP Code:
    "Respawns left"
    
{
        
"#format"    "{1:N},{2:d}"
        "en"    "{1}, you have {2} respawns left!"
        "se"    "{1}, du har {2} respawns kvar!"
    

or PrintToChat like this:
PHP Code:
 CPrintToChat(client"%s %t"prefix"Respawns left",  RespawnLeft[client]); 
__________________


Max-Play.pl - the best polish servers

Last edited by CamerDisco; 06-18-2017 at 08:26.
CamerDisco is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 06-18-2017 , 08:25   Re: Formatting in translations
Reply With Quote #5

Quote:
Originally Posted by 8guawong View Post
PHP Code:
#define prefix [PreFix] 
Because it's fun to recompile whole plugin if you want to change the prefix...
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 06-18-2017 , 08:44   Re: Formatting in translations
Reply With Quote #6

Quote:
Originally Posted by KissLick View Post
Btw. isn't there a difference between %t and %T ?
- Yes, use %T
What is the difference? I used %T before and it gave some errors, maybe used it in the wrong context?
__________________
condolent is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 06-18-2017 , 09:23   Re: Formatting in translations
Reply With Quote #7

Quote:
Originally Posted by condolent View Post
What is the difference? I used %T before and it gave some errors, maybe used it in the wrong context?
I could be wrong but this is an educated guess:
%t uses the global translation target (I believe PrintToChat and similars set the global target to the client before formatting)
%T requires at least 2 arguments, the translation key + translation target (which is what your original post is designed for).

Edit: Looks like a few natives doesn't set the global target to receiving client (PrintToConsole looks like one of them).
__________________

Last edited by WildCard65; 06-18-2017 at 09:27.
WildCard65 is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 06-18-2017 , 09:25   Re: Formatting in translations
Reply With Quote #8

Quote:
Originally Posted by WildCard65 View Post
I could be wrong but this is an educated guess:
%t uses the global translation target (I believe PrintToChat and similars set the global target to the client before formatting)
%T requires at least 2 arguments, the translation key + translation target (which is what your original post is designed for).
Oooh, I see! So then what I only need to do is change %t to %T, nothing in the translation-file correct?
__________________
condolent is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 06-18-2017 , 09:28   Re: Formatting in translations
Reply With Quote #9

Quote:
Originally Posted by condolent View Post
Oooh, I see! So then what I only need to do is change %t to %T, nothing in the translation-file correct?
For example line you used in original post, yes.
__________________
WildCard65 is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 06-18-2017 , 09:28   Re: Formatting in translations
Reply With Quote #10

It all works now! Thanks, folks

BTW, what would you guys think is preferable? Global translation or client translation? I'm guessing global translation target is the servers' language setting
__________________

Last edited by condolent; 06-18-2017 at 09:29.
condolent is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:20.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode