Skip to content

Commit

Permalink
fix: Add advanced formatting docs (#190)
Browse files Browse the repository at this point in the history
* Add advanced formatting docs

* Use localizeMarkup
  • Loading branch information
bearfriend authored Aug 23, 2024
1 parent cfb640f commit 3735e17
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,16 +340,38 @@ Similarly `<em>` *emphasizes* a particular piece of text (browsers show this vis

Example:

```json
```javascript
{
"myMessage": "This is <b>bold</b> but <em>not</em> all that <strong>important</strong>."
myMessage: "This is <b>bold</b> but <em>not</em> all that <strong>important</strong>."
}
```

#### Advanced Formatting

More advanced formatting can be achieved by providing replacement methods for custom tags, which are similar to arguments:

```javascript
localizer.localizeHTML('myMessage');
{
goHome: "Go <homeLink>home</homeLink>"
}
```

Then, import `localizeMarkup`:
```javascript
import { localizeMarkup } from '@brightspace-ui/intl/lib/localize.js';
```

and provide a tag replacement method:
```javascript
localizer.localizeHTML('goHome', {
homeLink: chunks => localizeMarkup`<d2l-link href="/home">${chunks}</d2l-link>`
});
```
In addition to the Basic Formatting elements, these additional elements may also be used in replacement methods:

* `<d2l-link>`
* `<d2l-tooltip-help>`

### `onResourcesChange`
Provide an `onResourcesChange` callback function to perform tasks when the document language is changed and updated resources are available:

Expand Down

0 comments on commit 3735e17

Please sign in to comment.