We use the unpkg CDN
In the past we deployed the locizify script to our own CDN space. While this was ok migrating over to https://unpkg.com allows us to provide you an improved usage. In the past your code was bound to the latest deployed script on our CDN. As we strongly respect semver we just were able to update the script with non breaking updates.
Now as you could use the source from unpkg you're able to fix the version in your code like:
1 | https://unpkg.com/locizify // latest |
full sample:
1 | <script id="locizify" projectid="[PROJECT_ID]" |
New Features
merging
Sometimes you want to keep innerHTML of an element together to make it easier to translate.
Before:
1 | <p>Might be easier to translate this <a href="#">the new way</a></p> |
1 | // resulting keys |
Using merge:
1 | <p merge>Might be easier to translate this <a href="#">the new way</a></p> |
1 | // resulting keys |
While you can set the merge
attribute on every element you like to have this behaviour. You can also specify this globally on init:
1 |
|
cleanup for keys
With v2 we improved the key generation from content by removing unused whitespaces:
Before:
1 | <p> |
1 | // resulting keys |
Using cleanup (default enabled in v2):
1 | <p> |
1 | // resulting keys |
All the unnecessary whitespaces get removed making translation more easy. You can manually toggle this off or ignore it for certain tags:
1 |
|
Fragment replacement for links and images
1 | <img src="/images/{{a.png}}" alt="big A" /> |
You will find a.png
and statistic
to be a key in your translations - it's value can be replaced to eg. a-de.png for german (all other languages will fallback to a.png)
Translate other then default attributes on elements
eg: for validation error messages
1 | <input data-parsley-error-message="This field is required" /> |
Just add data-parsley-error-message
to the translateAttributes
Array on init:
1 |
|
You can define rules like:
``[attributeToTranslate]#element.andOrAttributeWithValue`
1 | value#input // all values on input |
Migration from v1
To make v2 having the same behaviour as v1 you could change the init options like:
1 |
|
This way you assert keys get not cleaned of whitespaces so they match the counterpart of v1.