4

I am using uploadcare widget in my angularjs-based application. I integrated this widget as angular directive.

Documentation said, that I should set global variable to change locale:

<script>
    UPLOADCARE_LOCALE = 'ru';
</script>

But I am not very familiar with angular. So, I have no idea how do it dynamically.

I'll be glad of any help.

Update


I tryed to add $rootScope to my uploadcare directive and set UPLOADCARE_LOCALE variable there:

angular.module("project").directive 'projectUploadcare', ($uploadcare, $rootScope) ->
   restrict: 'E'
   replace: true
   template: '''
                <span>
                   <span class="uploadcare-preview"></span>
                   <input type="hidden">
                </span>
             '''
   link: (scope, element, attrs) ->
      $rootScope.UPLOADCARE_LOCALE = 'ru'
      ... other code ...

but it does not help.

Sergey
  • 1,059
  • 3
  • 21
  • 35

2 Answers2

5

All global settings are read one time at page loading. Locale is global setting and can't be overwritten for particular widget. But according to source there is a hack which allows one to rebuild translation at runtime.

First, you need to acquire internal Uploadcare API.

var internalUploadcare;
uploadcare.plugin(function(internal) {
  internalUploadcare = internal;
});

Then you can use internal internalUploadcare.locale.rebuild method to rebuild locale settings. Third step is reinitialize your existing widgets on the page. For example:

$('#uploader').html(
  $('#uploader input:eq(0)')
);
uploadcare.initialize($('#uploader'));

Add all together: http://jsbin.com/comone/1/watch

Dmitry Mukhin
  • 6,649
  • 3
  • 29
  • 31
homm
  • 2,102
  • 1
  • 16
  • 33
0

by manual you should use

UPLOADCARE_LOCALE_TRANSLATIONS = {
  errors: {
    'portrait': 'Landscape images only'  // message for widget
  },
  dialog: {tabs: {preview: {error: {
    'portrait': {  // messages for dialog's error page
      title: 'No portrait images are allowed.',
      text: 'We are sorry but image should be landscape.',
      back: 'Back'
    }
  } } } }
};

and yes:

UPLOADCARE_LOCALE = 'en';

just be sure that you set this variable BEFORE.

but it's nothing to do with AngularJS

Stepan Suvorov
  • 25,118
  • 26
  • 108
  • 176