-
Notifications
You must be signed in to change notification settings - Fork 61
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
GitHub 144 localizable custom entities #148
Open
kanduvisla
wants to merge
5
commits into
FriendsOfAkeneo:master
Choose a base branch
from
kanduvisla:GITHUB-144_localizable_custom_entities
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3938b22
GITHUB-144: Exclude .idea folder
kanduvisla a94a7c6
GITHUB-144: Allow for localizable properties
kanduvisla bb5a5bf
GITHUB-144: Added JavaScript and Templates for localization of custom…
kanduvisla 1d22902
[TASK] Remove unused requirejs dependency
kanduvisla 916fd19
GITHUB-144: Translate label
kanduvisla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ vendor | |
composer.phar | ||
composer.lock | ||
docker-compose.yml | ||
.idea/ |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
define([ | ||
'pim/product-edit-form/locale-switcher', | ||
'underscore', | ||
'pim/i18n', | ||
'oro/translator', | ||
'pim/user-context', | ||
], function (LocalSwitcher, _, i18n, __, UserContext) { | ||
"use strict"; | ||
|
||
return LocalSwitcher.extend({ | ||
currentLocaleCode: null, | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
configure: function () { | ||
this.update(UserContext.get('uiLocale')); | ||
}, | ||
|
||
/** | ||
* Method triggered on the 'change locale' event | ||
* | ||
* @param {Object} event | ||
*/ | ||
changeLocale: function (event) { | ||
this.update(event.target.dataset.locale); | ||
}, | ||
|
||
/** | ||
* @param {String} localeCode | ||
*/ | ||
update: function(localeCode) { | ||
this.currentLocaleCode = localeCode; | ||
this.getRoot().trigger('custom_entity:form:custom:translatable:switcher:change', {localeCode: localeCode}); | ||
this.render(); | ||
}, | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
render: function () { | ||
this.getDisplayedLocales() | ||
.done(function (locales) { | ||
|
||
if (!this.currentLocaleCode) { | ||
this.currentLocaleCode = _.first(locales).code; | ||
} | ||
|
||
this.$el.html( | ||
this.template({ | ||
locales: locales, | ||
currentLocale: _.findWhere(locales, {code: this.currentLocaleCode}), | ||
i18n: i18n, | ||
displayInline: this.displayInline, | ||
displayLabel: this.displayLabel, | ||
label: __('pim_enrich.entity.product.meta.locale') | ||
}) | ||
); | ||
this.delegateEvents(); | ||
}.bind(this)); | ||
|
||
return this; | ||
}, | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
define([ | ||
'pim/common/properties/translation', | ||
'custom_entity/template/localizable/text', | ||
'pim/form', | ||
'underscore', | ||
'jquery', | ||
'pim/user-context', | ||
'oro/translator', | ||
], function (Translation, template, BaseForm, _, $, UserContext, __) { | ||
"use strict"; | ||
|
||
return Translation.extend({ | ||
template: _.template(template), | ||
localeCode: null, | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
configure: function () { | ||
this.listenTo( | ||
this.getRoot(), | ||
'pim_enrich:form:entity:pre_save', | ||
this.onPreSave | ||
); | ||
|
||
this.listenTo( | ||
this.getRoot(), | ||
'pim_enrich:form:entity:bad_request', | ||
this.onValidationError | ||
); | ||
|
||
this.listenTo( | ||
this.getRoot(), | ||
'pim_enrich:form:entity:locales_updated', | ||
this.onLocalesUpdated.bind(this) | ||
); | ||
|
||
this.listenTo( | ||
this.getRoot(), | ||
'custom_entity:form:custom:translatable:switcher:change', | ||
this.onLocaleChanged.bind(this) | ||
); | ||
|
||
return $.when( | ||
this.getLocales(true) | ||
.then(function (locales) { | ||
this.locales = locales; | ||
this.localeCode = UserContext.get('uiLocale'); | ||
}.bind(this)), | ||
BaseForm.prototype.configure.apply(this, arguments) | ||
); | ||
}, | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
render: function () { | ||
this.$el.html(this.template({ | ||
model: this.getFormData(), | ||
locales: this.locales, | ||
currentLocaleCode: this.localeCode, | ||
errors: this.validationErrors, | ||
label: __(this.config.label), | ||
fieldName: this.config.fieldName, | ||
isReadOnly: this.isReadOnly() | ||
})); | ||
|
||
this.delegateEvents(); | ||
this.renderExtensions(); | ||
}, | ||
|
||
/** | ||
* @param {{}} context | ||
*/ | ||
onLocaleChanged: function (context) { | ||
this.localeCode = context.localeCode; | ||
this.render(); | ||
}, | ||
|
||
/** | ||
* @param {Object} event | ||
*/ | ||
updateModel: function (event) { | ||
var data = this.getFormData(); | ||
|
||
if (Array.isArray(data[this.config.fieldName])) { | ||
data[this.config.fieldName] = {}; | ||
} | ||
|
||
data[this.config.fieldName][event.target.dataset.locale] = event.target.value; | ||
|
||
this.setData(data); | ||
}, | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
define([ | ||
'custom_entity/form/localizable/text', | ||
'custom_entity/template/localizable/textarea' | ||
], function (Text, template) { | ||
"use strict"; | ||
|
||
return Text.extend({ | ||
template: _.template(template) | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<% _.each(locales, function (locale) { %> | ||
<% if (currentLocaleCode === locale.code) { %> | ||
<div class="AknFieldContainer"> | ||
<div class="AknFieldContainer-header"> | ||
<label class="AknFieldContainer-label" for="<%- fieldName %><%- locale.code %>"> | ||
<%= label %> | ||
</label> | ||
<% var langCode = locale.code.split('_')[1].toLowerCase() %> | ||
<span class="AknFieldContainer-fieldInfo field-info"> | ||
<span class="field-context"> | ||
<span> | ||
<span class="flag-language"> | ||
<i class="flag flag-<%- langCode %>"></i> | ||
<span class="language"><%- langCode %></span> | ||
</span> | ||
</span> | ||
</span> | ||
</span> | ||
</div> | ||
<div class="AknFieldContainer-inputContainer field-input"> | ||
<div class="AknTextField-layer AknTextField-layer--first"></div> | ||
<div class="AknTextField-layer AknTextField-layer--second"></div> | ||
<input id="<%- fieldName %><%- locale.code %>" | ||
class="AknTextField AknTextField--localizable label-field" | ||
type="text" | ||
data-locale="<%- locale.code %>" | ||
value="<%- model[fieldName][locale.code] %>" | ||
<%- isReadOnly ? 'readonly disabled' : '' %> | ||
> | ||
</div> | ||
<% if (errors[locale.code]) { %> | ||
<div class="AknFieldContainer-footer"> | ||
<span class="validation-error"> | ||
<i class="icon-warning-sign"></i> | ||
<span class="error-message"><%- errors[locale.code].message %></span> | ||
</span> | ||
</div> | ||
<% } %> | ||
</div> | ||
<% } %> | ||
<% }) %> |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug :
provokes an error
An error occurred during the export execution.