From c94ab1a05daa0c3228866c073bcd2be61b56cb70 Mon Sep 17 00:00:00 2001 From: Jason Irish Date: Mon, 3 Jun 2019 23:25:36 -0500 Subject: [PATCH] initial i18n implementation fixes #13 --- .tx/config | 10 ++++++++++ README.md | 6 ++++++ lang/_manifest_exclude | 0 lang/en.yml | 17 +++++++++++++++++ src/Elements/ElementFileList.php | 23 +++++++++++++---------- src/Model/FileListObject.php | 20 +++++++++++++++++++- 6 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 .tx/config create mode 100644 lang/_manifest_exclude create mode 100644 lang/en.yml diff --git a/.tx/config b/.tx/config new file mode 100644 index 0000000..71f3172 --- /dev/null +++ b/.tx/config @@ -0,0 +1,10 @@ +[main] +host = https://www.transifex.com + +[silverstripe-elemental-filelist.en-yml] +file_filter = lang/.yml +minimum_perc = 0 +source_file = lang/en.yml +source_lang = en +type = YAML_GENERIC + diff --git a/README.md b/README.md index 4f0841e..2d409bb 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,12 @@ Elemental FileList Block will add the following Element to your site: The FileList Element will display a list of files for download. +## Translations + +The translations for this project are managed via [Transifex](https://www.transifex.com/dynamicagency/silverstripe-elemental-filelist/) +and are updated automatically during the release process. To contribute, please head to the link above and get +translating! + ## Maintainers * [Dynamic](http://www.dynamicagency.com) () diff --git a/lang/_manifest_exclude b/lang/_manifest_exclude new file mode 100644 index 0000000..e69de29 diff --git a/lang/en.yml b/lang/en.yml new file mode 100644 index 0000000..480aaeb --- /dev/null +++ b/lang/en.yml @@ -0,0 +1,17 @@ +en: + Dynamic\Elements\FileList\Elements\ElementFileList: + FilesLabel: 'Files' + PLURALNAME: 'File List Elements' + PLURALS: + one: 'A File List' + other: '{count} File Lists' + SINGULARNAME: 'File List Element' + Dynamic\Elements\FileList\Model\FileListObject: + FileLabel: 'File' + FileNameLabel: 'File' + PLURALNAME: 'Files' + PLURALS: + one: 'A File' + other: '{count} Files' + SINGULARNAME: 'File' + TitleLabel: 'Title' diff --git a/src/Elements/ElementFileList.php b/src/Elements/ElementFileList.php index f79e342..e227aff 100644 --- a/src/Elements/ElementFileList.php +++ b/src/Elements/ElementFileList.php @@ -18,16 +18,6 @@ class ElementFileList extends BaseElement */ private static $icon = 'font-icon-block-file-list'; - /** - * @var string - */ - private static $singular_name = 'File List Element'; - - /** - * @var string - */ - private static $plural_name = 'File List Elements'; - /** * @var string */ @@ -52,6 +42,19 @@ class ElementFileList extends BaseElement */ private static $inline_editable = false; + /** + * @param bool $includerelations + * @return array + */ + public function fieldLabels($includerelations = true) + { + $labels = parent::fieldLabels($includerelations); + + $labels['Files'] = _t(__CLASS__.'.FilesLabel', 'Files'); + + return $labels; + } + /** * @return FieldList */ diff --git a/src/Model/FileListObject.php b/src/Model/FileListObject.php index bfee308..fd5a10a 100644 --- a/src/Model/FileListObject.php +++ b/src/Model/FileListObject.php @@ -46,10 +46,25 @@ class FileListObject extends DataObject * @var array */ private static $summary_fields = [ - 'File.Name' => 'File', + 'File.Name', 'Title', ]; + /** + * @param bool $includerelations + * @return array + */ + public function fieldLabels($includerelations = true) + { + $labels = parent::fieldLabels($includerelations); + + $labels['Title'] = _t(__CLASS__.'.TitleLabel', 'Title'); + $labels['File.Name'] = _t(__CLASS__.'.FileNameLabel', 'File'); + $labels['File'] = _t(__CLASS__.'.FileLabel', 'File'); + + return $labels; + } + /** * @var string */ @@ -62,6 +77,9 @@ public function getCMSFields() { $fields = parent::getCMSFields(); + $fields->dataFieldByName('File') + ->setTitle($this->fieldLabel('File')); + $fields->removeByName([ 'FileListID', 'SortOrder',