$string=ts("Hi %2, how are you?",array(1=>$name));
if($is_early){
$string=ts("Good morning %2, how are you?",array(1=>$name));
// Less bad:
// Note that this still makes it difficult to use the correct gender.
if(empty($params['id'])){
$string=ts("New %1",array(1=>$contactType));
}
else{
$string=ts("Edit %1",array(1=>$contactType));
}
```
## Javascript
When translating strings in an extension, ts scope needs to be declared. The CRM.ts function takes scope as an argument and returns a function that always applies that scope to ts calls:
```js
// This closure gets a local copy of jQuery, Lo-dash, and ts
(function($,_,ts){
CRM.alert(ts('Your foo has been barred.'));
})(CRM.$,CRM._,CRM.ts('foo.bar.myextension'));
```
Note that `CRM.ts` is not the same as the global `ts` function. `CRM.ts` is a function that returns a function (javascript is wacky like that). Since your closure gives the local `ts` the same name as the global `ts`, it will be used instead.
Important: Your local version of `ts` could be named anything, but strings in your javascript file cannot be accurately parsed unless you name it ts.
## Smarty templates
The strings hard-coded into templates should be wrapped in `{ts}...{/ts}` tags. For example:
```
{ts}Full or partial name (last name, or first name, or organization name).{/ts}
```
If you need to pass a variable to the localisable string, you should use the following pattern:
```
<div class="status">{ts 1=$delName}Are you sure you want to delete <b>%1</b> Tag?{/ts}</div>
```
When possible, avoid HTML formatting and newlines inside `{ts}...{/ts}` tags. For example: