Skip to content

Commit

Permalink
[core] fix #1012 support i18n folder name
Browse files Browse the repository at this point in the history
**connector** added an option `i18nFolderName`

```php
// enable i18n folder name that convert name to elFinderInstance.messages['folder_'+name]
'i18nFolderName'  => false,
```

**e.g. connector.php**

```php
$opts = array(
    'roots'  => array(
        array(
            'driver'         => 'LocalFileSystem',
            'path'           => '/path/to/files/',
            'i18nFolderName' => true,
        )
    )
);

// run elFinder
$connector = new elFinderConnector(new elFinder($opts));
$connector->run();
```

**e.g. elfinder.html**

```javascript
// Additional translation messages
var i18nFolderMsgs = {
    'en': {
        'folder_Downloads':   'Downloads',
        'folder_Images':      'Images',
        'folder_LargeVideos': 'Videos',
        'folder_MIME-types':  'MIME types',
        'folder_Welcome':     'Welcome(Multilingual)'
    },
    'jp': {
        'folder_Downloads':   'ダウンロード',
        'folder_Images':      '画像',
        'folder_LargeVideos': '動画',
        'folder_MIME-types':  'MIMEタイプ',
        'folder_Welcome':     'ようこそ(多言語)'
    }
};

var options = {
    url      : 'php/connector.php',
    handlers : {
        init : function(e, fm) {
            // Register additional messages
            $.extend(fm.messages, i18nFolderMsgs.en, i18nFolderMsgs[fm.lang] || {});
        }
    }
}

$('#elfinder').elfinder(options);
```
  • Loading branch information
nao-pon committed Jul 20, 2016
1 parent 0fdd558 commit 5a9c267
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 49 deletions.
2 changes: 1 addition & 1 deletion js/commands/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ elFinder.prototype.commands.rename = function() {
})
.fail(function(error) {
var parent = input.parent(),
name = fm.escape(file.name);
name = fm.escape(file.i18 || file.name);

if (tarea) {
name = name.replace(/([_.])/g, '​$1');
Expand Down
107 changes: 67 additions & 40 deletions js/elFinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,6 @@ window.elFinder = function(node, opts) {
for (i = 0; i < l; i++) {
f = data[i];
if (f.name && f.hash && f.mime) {
if (!f.phash) {
var name = 'volume_'+f.name,
i18 = self.i18n(name);

if (name != i18) {
f.i18 = i18;
}
}
if (sorterChk && f.phash === cwd) {
$.each(self.sortRules, function(key) {
if (defsorter[key] || typeof f[key] !== 'undefined' || (key === 'mode' && typeof f.perm !== 'undefined')) {
Expand Down Expand Up @@ -4422,39 +4414,70 @@ elFinder.prototype = {
var self = this,
filter = function(file) {

if (file && file.hash && file.name && file.mime) {
if (file.mime == 'application/x-empty') {
file.mime = 'text/plain';
}
// set options, tmbUrls for each volume
if (file.volumeid) {
// from v2.1.14
if (file.options) {
// set volOptions
self.volOptions[file.volumeid] = file.options;
if (file && file.hash && file.name && file.mime) {
if (file.mime == 'application/x-empty') {
file.mime = 'text/plain';
}

if (! file.phash || file.mime === 'directory') {
// set options, tmbUrls for each volume
if (file.volumeid) {
// from v2.1.14
if (file.options) {
// set volOptions
self.volOptions[file.volumeid] = file.options;

// set immediate properties
$.each(self.optionProperties, function(i, k) {
if (file.options[k]) {
file[k] = file.options[k];
}
});
} else {
// for compat <= v2.1.13
if (file.disabled) {
self.volOptions[file.volumeid].disabled = file.disabled;
}
if (file.tmbUrl) {
self.volOptions[file.volumeid].tmbUrl = file.tmbUrl;
}
}
if (! file.phash) {
self.roots[file.volumeid] = file.hash;
}

if (prevId !== file.volumeid) {
prevId = file.volumeid;
i18nFolderName = self.option('i18nFolderName', file.volumeid);
}
}

// set immediate properties
$.each(self.optionProperties, function(i, k) {
if (file.options[k]) {
file[k] = file.options[k];
// volume root i18n name
if (! file.i18 && ! file.phash) {
name = 'volume_' + file.name,
i18 = self.i18n(false, name);

if (name !== i18) {
file.i18 = i18;
}
});
} else {
// for compat <= v2.1.13
if (file.disabled) {
self.volOptions[file.volumeid].disabled = file.disabled;
}
if (file.tmbUrl) {
self.volOptions[file.volumeid].tmbUrl = file.tmbUrl;

// i18nFolderName
if (i18nFolderName && ! file.i18) {
name = 'folder_' + file.name,
i18 = self.i18n(false, name);

if (name !== i18) {
file.i18 = i18;
}
}
}
self.roots[file.volumeid] = file.hash;

return file;
}

return file;
}
return null;
};
return null;
},
name, i18, i18nFolderName, prevId;


if (data.files) {
Expand Down Expand Up @@ -4947,9 +4970,13 @@ elFinder.prototype = {
}
return m;
},
i, j, m;

for (i = 0; i< arguments.length; i++) {
i, j, m, escFunc, start = 0;

if (arguments.length && arguments[0] === false) {
escFunc = function(m){ return m; };
start = 1;
}
for (i = start; i< arguments.length; i++) {
m = arguments[i];

if (typeof m == 'string') {
Expand Down Expand Up @@ -4977,14 +5004,14 @@ elFinder.prototype = {
m = input[i];
if (typeof m == 'string') {
// translate message
m = messages[m] || self.escape(m);
m = messages[m] || (escFunc? escFunc(m) : self.escape(m));
// replace placeholders in message
m = m.replace(/\$(\d+)/g, function(match, placeholder) {
placeholder = i + parseInt(placeholder);
if (placeholder > 0 && input[placeholder]) {
ignore.push(placeholder)
}
return self.escape(input[placeholder]) || '';
return escFunc? escFunc(input[placeholder]) : self.escape(input[placeholder]);
});
} else {
// get HTML from jQuery object
Expand Down
6 changes: 3 additions & 3 deletions js/ui/cwd.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ $.fn.elfindercwd = function(fm, options) {
return fm.cwdHash2Id(f.hash);
},
name : function(f) {
var name = fm.escape(f.name);
var name = fm.escape(f.i18 || f.name);
!list && (name = name.replace(/([_.])/g, '&#8203;$1'));
return name;
},
nametitle : function(f) {
return fm.escape(f.name);
return fm.escape(f.i18 || f.name);
},
permsclass : function(f) {
return fm.perms2class(f);
Expand Down Expand Up @@ -265,7 +265,7 @@ $.fn.elfindercwd = function(fm, options) {
info = f.tooltip? fm.escape(f.tooltip).replace(/\r/g, '&#13;') : '';
}
if (list) {
info += (info? '&#13;' : '') + fm.escape(f.name);
info += (info? '&#13;' : '') + fm.escape(f.i18 || f.name);
}
return info? info + '&#13;' + title : title;
}
Expand Down
5 changes: 3 additions & 2 deletions js/ui/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ $.fn.elfinderpath = function(fm) {
$.each(roots, function(i, f) {
if (fm.root(fm.cwd().hash) !== f.hash) {
raw.push({
label : f.name,
label : fm.escape(f.i18 || f.name),
icon : 'home',
remain : true,
callback : function() { fm.exec('open', f.hash); }
Expand All @@ -56,7 +56,8 @@ $.fn.elfinderpath = function(fm) {
var dirs = [];
$.each(fm.parents(cwd), function(i, hash) {
var c = (cwd === hash)? 'elfinder-path-dir elfinder-path-cwd' : 'elfinder-path-dir',
name = fm.escape(fm.file(hash).name);
f = fm.file(hash),
name = fm.escape(f.i18 || f.name);
dirs.push('<span id="'+prefix+hash+'" class="'+c+'" title="'+name+'">'+name+'</span>');
});
return dirs.join('<span class="elfinder-path-other">'+fm.option('separator')+'</span>');
Expand Down
4 changes: 2 additions & 2 deletions js/ui/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ $.fn.elfindertree = function(fm, opts) {
info = fm.file(fm.navId2Hash(node.children('[id]').attr('id')));

if ((info = fm.file(fm.navId2Hash(node.children('[id]').attr('id'))))
&& compare(dir.name, info.name) < 0) {
&& compare(dir.i18 || dir.name, info.i18 || info.name) < 0) {
return node;
}
node = node.next();
Expand Down Expand Up @@ -397,7 +397,7 @@ $.fn.elfindertree = function(fm, opts) {
*
*/
compare = function(dir1, dir2) {
return fm.naturalCompare(dir1.name, dir2.name);
return fm.naturalCompare(dir1.i18 || dir1.name, dir2.i18 || dir2.name);
},

/**
Expand Down
5 changes: 4 additions & 1 deletion php/elFinderVolumeDriver.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ abstract class elFinderVolumeDriver {
'icon' => '',
// CSS Class of volume root in tree
'rootCssClass' => '',
// enable i18n folder name that convert name to elFinderInstance.messages['folder_'+name]
'i18nFolderName' => false,
// Search timeout (sec)
'searchTimeout' => 30,
// Search exclusion directory regex pattern (require demiliter e.g. '#/path/to/exclude_directory#i')
Expand Down Expand Up @@ -1343,7 +1345,8 @@ public function options($hash) {
),
'uiCmdMap' => (isset($this->options['uiCmdMap']) && is_array($this->options['uiCmdMap']))? array_values($this->options['uiCmdMap']) : array(),
'syncChkAsTs' => intval($this->options['syncChkAsTs']),
'syncMinMs' => intval($this->options['syncMinMs'])
'syncMinMs' => intval($this->options['syncMinMs']),
'i18nFolderName' => intval($this->options['i18nFolderName'])
);
if ($hash === null) {
// call from getRootStatExtra()
Expand Down

0 comments on commit 5a9c267

Please sign in to comment.