-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Localize from object #94
Open
LonelyPrincess
wants to merge
10
commits into
coderifous:master
Choose a base branch
from
LonelyPrincess:localize-from-object
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Localize from object #94
LonelyPrincess
wants to merge
10
commits into
coderifous:master
from
LonelyPrincess:localize-from-object
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
New code has been added so that raw javascript objects can now be used as a source for the translations. If localize receives an object as a first parameter, items with 'data-localize' tags will be updated with the text contained in the matching object properties. Said object will be converted to a valid json object beforehand, so no problems shall arise if the given object include functions as a value for any of its keys. In the case localize method receives any parameter that is not an object, the default behaviour where the translations are retrieved from an external file will be applied. This should solve the following issue: coderifous#62
The method that replace the localized tags by the texts defined inside of a raw object did not consider any of the possible options you could receive as a second parameter in a 'localize' call. The 'callback' option is now supported. The 'data' object will be converted to a valid json object before calling the default callback, so if the user sets any of the data properties to a function, the elements for which the 'data-localize' attribute references any of those invalid property values will not be updated. The 'localize_test.coffee' file do now include new methods to test the new functionality. The 'localize_from_object.html' has been also updated and seems to be working as expected in the following browsers: - Google Chrome (59.0.3071.115) - Mozilla Firefox (45.0, 47.0.1) - Microsoft Edge (40.15063.0.0)
I've added a new example to illustrate on how to call localize by passing the response of a webservice as an argument to 'jquery-localize'. Both of the examples created for this new feature have been moved to a new 'objectDS' folder, as to keep them separated from the default examples.
Since we want the examples to be fully functional and show how the library is meant to be used, I've removed the properties for which I've assigned a function as their value. Still, the sanitizer callback will be kept and so will the test to guarantee that there will be no problem if the user passes an object that include a function among their keys.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Until now the plugin did only allow to localize contents from a json file that followed a certain naming guidelines. With the proposed changes, the
localize
method can now receive an object as a parameter, instead of the name of a language pack.This feature might be useful if you'll be retrieving your texts from an external service whose url doesn't match the
"{pathPrefix}/{filename}-{lang}.{extension}"
syntax.The new code will only be applied when the received parameter is an object: otherwise, the plugin will expect the parameter to be a language pack name and keep its default behavior. The
README.md
file has been updated explaining the new feature, and I've also included a new subdirectory in the examples folder to illustrate how it works.This set of changes should solve issue #62.