Jump to content
cidfr

Using formatted localized strings with BIS_fnc_taskCreate

Recommended Posts

Hello,

 

Consider this key in the stringtable :

 

<Key ID="STR_CID_FREE_CITY_TASK_DESCRIPTION">
  <English>Clear %1 of ennemies</English>
  <!-- more languages -->
</Key>

 

Using a local context, I can easily do :

private _localizedDescription = format [ localize "STR_CID_FREE_CITY_TASK_DESCRIPTION", _cityName ];

 

However, I'm wondering if it's possible to use such strings with BIS_fnc_taskCreate

 

I could do 

[
  _side,
  _taskID,
  [
    format [ localize "STR_CID_FREE_CITY_TASK_DESCRIPTION", _cityName ],
    "some title", // could be localized too
    ""
  ]
] call BIS_fnc_taskCreate;

 

But this will be evaluated server-side and the clients may receive strings in a language that doesn't match theirs

 

I could remotely send the tasks creation on each clients with

[
  [ _side, _taskID, _cityName ],
  {
    [ /* same parameters than previous code */ ] call BIS_fnc_taskCreate;
  }
] remoteExec [ "spawn", 0, true ];

 

This may work, but will require extra work to sync the tasks between the clients and the server, update the JIP queue when a task has changed and probably more stuff

And in my opinion, this will goes against the purpose of using the Task Framework, which already handle all of this and can send static localized strings to clients

 

So far, the only clean solution I found was changing the description to a generic "Clear the zone of ennemies" and as title the _cityName. This is acceptable, but I was wondering if using formatted localized strings was possible using the Task Framework

 

Thanks

Share this post


Link to post
Share on other sites

No need to format or localize the text yourself the Task Framework already handles all this for you, for both the Description and Title.

<Key ID="STR_CID_FREE_CITY_TASK_DESCRIPTION">
  <English>Clear %1 of %2</English>
  <!-- more languages -->
</Key>

<Key ID="STR_CID_FREE_CITY_TASK_TITLE">
  <English>Clear %1</English>
  <!-- more languages -->
</Key>
_objective = "enemies";

[
  _side,
  _taskID,
  [
  	//Format array, string to be localised, parameters for format %1, %2 ...
    [ "STR_CID_FREE_CITY_TASK_DESCRIPTION", _cityName, _objective ],
    [ "STR_CID_FREE_CITY_TASK_TITLE", _cityName ],
    ""
  ]
] call BIS_fnc_taskCreate;

 

On 3/1/2024 at 7:36 PM, cidfr said:

But this will be evaluated server-side and the clients may receive strings in a language that doesn't match theirs

The localisation in the Task Framework happens on each client, so it will be different based on the client's language.

 

The only thing not localised is the format parameters.

 

Excerpt from BIS_fnc_setTaskLocal..

Spoiler

private _fnc_localize =
	{
		if (typeName _this == typeName "") then
		{
			if (isLocalized _this) then {localize _this} else {_this};
		}
		else
		{
			private _array =+ _this;
			private _text = _array select 0;

			if (islocalized _text) then {_array set [0,localize _text];};

			if (count _array > 1) then
			{
				_array = format _array;
			}
			else
			{
				_array = _array select 0;
			};

			_array
		};
	};

	//snip

	/*--------------------------------------------------------------------------------------------------

		Preprocess data

	--------------------------------------------------------------------------------------------------*/

	//localize task texts
	_description = _description call _fnc_localize;
	_title = _title call _fnc_localize;
	_marker = "";

 

 

I have put in a ticket for a tweak to allow the localisation of format parameters as well.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Thank you, Larrow !

 

 

2 hours ago, Larrow said:

No need to format or localize the text yourself the Task Framework already handles all this for you, for both the Description and Title.

 

This should be added in the documentation, which is often lacking of many precisions.

I usually read the source code when I need clarification and for once I don't do it, the answer was in the code... 😅

Share this post


Link to post
Share on other sites
18 hours ago, cidfr said:

This should be added in the documentation,

Done, updated parameter info and added an example.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×