usage of dynamic place holder in "strings.txt"

Ask community to help.

Moderators: Amaradana, TurboPT, TL Developers

usage of dynamic place holder in "strings.txt"

Postby yuryP » Fri Jul 15, 2016 8:16 am

hi folks,

in the "strings.txt", that is located under "./locale/en_GB/", appear in templates for messages various dynamic place holder like '%s', '{%1}'.

could anybody explain me how they can be used or where i can find futher Inforamtion (mapping etc.) about this feature?

background: i'd like to customize/overwrite some of them in "custom_strings.txt".

we use TestLink 1.9.14

thank you for your assistance
regards
yury
yuryP
TestLink user
 
Posts: 12
Joined: Thu Jul 30, 2015 6:28 pm

Re: usage of dynamic place holder in "strings.txt"

Postby TurboPT » Thu Jan 26, 2017 10:09 pm

Though the original post is now several months old, I'll show a high-level basic example use of each, below, for informational reference for those that might not be familiar with the syntax/usage...

The %s is used with certain print-format functions, such as sprintf().
  • Know that there are other "format specifiers" available, not only %s.
  • There are also other functions that use the specifiers in a similar manner. Refer to the "See Also" section in the above sprintf link.
The %1 [%2, etc] is used with variable function argument/parameter counts.

=========

An example with the [function argument/parameter] numbers %1, %2, etc:

From en_GB/strings.txt:
Code: Select all
...
$TLS_audit_login_succeeded = "Login for '{%1}' from '{%2}' succeeded";
...

...then in file login.php, we can find:
Code: Select all
    // Login successful, redirect to destination
    logAuditEvent(TLS("audit_login_succeeded",$argsObj->login,
                  $_SERVER['REMOTE_ADDR']),"LOGIN",$_SESSION['currentUser']->dbID,"users");

...the portion of interest is the first parameter to logAuditEvent() which is a call to TLS().

TLS is passed a string reference along with the login and IP address. The login ultimately replaces %1 and the IP address replaces the %2 to complete the string.

The TLS() definition is in file: /lib/functions/metastring.class.php. Look there to see how the arguments are gathered.

===========

Now a %s example:

From en_GB/strings.txt:
Code: Select all
...
$TLS_importViaAPI = "Import via API (%s)";
...

...we can find that string being used in file: /lib/requirements/reqSpecView.php
Code: Select all
...
    $gui->btn_import_req_spec = sprintf(lang_get('importViaAPI'),$reqMgrSystem['reqmgrsystem_name']);
...

...so to the sprintf, the first function argument is the string [which contains the %s format], and the second function argument is what replaces the %s to complete the string.

HTH.
TurboPT
Member of TestLink Community
 
Posts: 337
Joined: Sun Dec 10, 2006 4:51 am


Return to Installation and configuration



Who is online

Users browsing this forum: No registered users and 2 guests

cron