Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

provide axLocalize directive #38

Closed
x1B opened this issue Mar 10, 2017 · 2 comments
Closed

provide axLocalize directive #38

x1B opened this issue Mar 10, 2017 · 2 comments

Comments

@x1B
Copy link
Member

x1B commented Mar 10, 2017

It was determined that axI18n is not big enough in LaxarJS v2 to warrant a standalone module (since the UiKit related i18n stuff is now part of laxar-uikit, again).

What remains is basically axLocalize. If feasible, let's try to find a LaxarJS v1 compatible solution based on the axI18n injection.

@x1B
Copy link
Member Author

x1B commented Mar 10, 2017

Implemented on master (v2.0.0).

BREAKING CHANGE

Note: Strictly speaking, this is not a breaking change within the adapter, but rather a breaking change to LaxarJS UiKit, where the axLocalize directive was kept previously. However, this changelog entry contains the actual, required upgrade information:

The AngularJS directive axLocalize, previously provided by LaxarJS UiKit, is now provided by the laxar-angular-adapter. The way the directive works was changed as well:

  • Previously, the filter took a second parameter i18n which was used to read the current localization information from the scope chain.

  • Now, the filter still takes a second parameter i18n, but expects this to be an axI18n widget service instance. Widgets can simply have this service injected, while directives can access it via axWidgetServices.

Previous Usage (LaxarJS v1)

In the widget controller:

function Controller( $scope ) {
   // This creates $scope.i18n *implicitly*
   var localize = patterns.i18n.handlerFor( $scope ).scopeLocaleFromFeature( 'i18n', {
      onChange: function() {
         $scope.localValue = localize( $scope.features.someI18nValue );
      }
   } ).localizer();
}

In the template:

<p>{{ localValue }}</p>
<p>{{ features.otherI18nValue | axLocalize:i18n }}</p>

New Usage (LaxarJS v2)

In the widget controller:

function Controller( $scope, axI18n ) {
   // Create $scope.i18n *explicitly*
   $scope.i18n = axI18n;
   axI18n.whenLocaleChanged( () => {
      $scope.localValue = axI18n.localize( $scope.features.someI18nValue );
   } );
}

The template looks just like before, but i18n is actually the service now:

<p>{{ localValue }}</p>
<p>{{ features.otherI18nValue | axLocalize:i18n }}</p>

More Breaking Changes

Together with LaxarJS/laxar#429, this has the following implications:

  • The value $rootScope.i18n is no longer meaningful, and is removed with LaxarJS v2.

  • The directive axBindLocale is also no longer needed. You can use axI18n.forFeature( ... ) to obtain different i18n instances and to use them with axLocalize or with other directives/controls.

@jpommerening
Copy link
Member

@x1B: Looks great! Care to push a draft so I can give it a try in LaxarJS/laxar-html-display-widget#11?

jpommerening added a commit to LaxarJS/laxar-html-display-widget that referenced this issue Mar 13, 2017
x1B added a commit that referenced this issue Mar 13, 2017
@x1B x1B closed this as completed Mar 13, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants