Skip to content

Commit

Permalink
Item14157: improve support to translate formfields
Browse files Browse the repository at this point in the history
... using MultiLingualPlugin
  • Loading branch information
MichaelDaum committed Sep 2, 2016
1 parent e15ef2f commit 5a7d422
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 38 deletions.
14 changes: 7 additions & 7 deletions .gitignore
@@ -1,9 +1,9 @@
*.gz
*.swp
FlexFormPlugin.md5
FlexFormPlugin.sha1
FlexFormPlugin.tgz
FlexFormPlugin.txt
FlexFormPlugin.zip
FlexFormPlugin_installer
FlexFormPlugin_installer.pl
/FlexFormPlugin.md5
/FlexFormPlugin.sha1
/FlexFormPlugin.tgz
/FlexFormPlugin.txt
/FlexFormPlugin.zip
/FlexFormPlugin_installer
/FlexFormPlugin_installer.pl
3 changes: 2 additions & 1 deletion data/System/FlexFormPlugin.txt
Expand Up @@ -20,7 +20,7 @@ be avoided by using a %<nop>RENDERFOREDIT macro that loops over all formfields i
to render the input form in a more dynamic way while still customizing the overall output.

In addition, !FlexFormPlugin facilitates the extraction of field default values (such as valid schema options) from
!DataForm. See http://foswiki.org/Development/MacroForRetrievingFieldDefaultValues for background.
!DataForm. See https://foswiki.org/Development/MacroForRetrievingFieldDefaultValues for background.

While %<nop>RENDERFOREDIT% and %<nop>%RENDERFORDISPLAY render forms for the net data using a !DataForm
the %<nop>RENDERFORMDEF= macro renders information about the !DataForm definition itself identpendent of
Expand Down Expand Up @@ -180,6 +180,7 @@ Note that the actual results may vary depending on the formfield type of the !Da
%$DEPENDENCIES%

---++ Change History
| 02 Sep 2016: | improved support to translate formfields using Foswiki:Extensions.MultiLingualPlugin |
| 08 Mar 2016: | clean up formfield title before trying to translate it; \
added =hideempty= for RENDERFOREDIT |
| 17 Jul 2015: | fixed use of =param()= in list context |
Expand Down
4 changes: 2 additions & 2 deletions lib/Foswiki/Plugins/FlexFormPlugin.pm
Expand Up @@ -18,8 +18,8 @@ package Foswiki::Plugins::FlexFormPlugin;
use strict;
use warnings;

our $VERSION = '5.20';
our $RELEASE = '08 Mar 2016';
our $VERSION = '5.21';
our $RELEASE = '02 Sep 2016';
our $SHORTDESCRIPTION = 'Flexible way to render <nop>DataForms';
our $NO_PREFS_IN_TOPIC = 1;
our $renderForEditInstance;
Expand Down
13 changes: 2 additions & 11 deletions lib/Foswiki/Plugins/FlexFormPlugin/Base.pm
Expand Up @@ -69,17 +69,8 @@ sub translate {
return "" unless defined $text && $text ne "";

return $text unless Foswiki::Func::getContext()->{MultiLingualPluginEnabled};

unless ($this->{translator}) {
require Foswiki::Plugins::MultiLingualPlugin;
$this->{translator} = Foswiki::Plugins::MultiLingualPlugin::getCore();
}

my $params = {
_DEFAULT => $text,
};

return $this->{translator}->TRANSLATE($this->{session}, $params, $topic, $web);
require Foswiki::Plugins::MultiLingualPlugin;
return Foswiki::Plugins::MultiLingualPlugin::translate($text, $web, $topic);
}

sub translateField {
Expand Down
1 change: 1 addition & 0 deletions lib/Foswiki/Plugins/FlexFormPlugin/DEPENDENCIES
@@ -0,0 +1 @@
Foswiki::Plugins::MultiLingualPlugin,>=3.00,perl,Optional
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/FlexFormPlugin/RenderForDisplay.pm
Expand Up @@ -226,7 +226,7 @@ sub handle {
$field = $fieldClone;
}

$fieldValue = $fieldDefault unless defined $fieldValue;
$fieldValue = $fieldDefault unless defined $fieldValue && $fieldValue ne '';
next if $theHideEmpty && (!defined($fieldValue) || $fieldValue eq '');

next if $theInclude && $fieldName !~ /$theInclude/;
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/FlexFormPlugin/RenderForEdit.pm
Expand Up @@ -245,7 +245,7 @@ sub handle {
$fieldValue = $metaField->{value} if $metaField;
}

$fieldValue = $fieldDefault unless defined $fieldValue;
$fieldValue = $fieldDefault unless defined $fieldValue && $fieldValue ne '';

next if $theInclude && $fieldName !~ /$theInclude/;
next if $theExclude && $fieldName =~ /$theExclude/;
Expand Down
16 changes: 1 addition & 15 deletions lib/Foswiki/Plugins/FlexFormPlugin/build.pl
@@ -1,24 +1,10 @@
#!/usr/bin/perl -w
#!/usr/bin/env perl
BEGIN { unshift @INC, split( /:/, $ENV{FOSWIKI_LIBS} ); }
use Foswiki::Contrib::Build;

# Create the build object
$build = new Foswiki::Contrib::Build('FlexFormPlugin');

# (Optional) Set the details of the repository for uploads.
# This can be any web on any accessible Foswiki installation.
# These defaults will be used when expanding tokens in .txt
# files, but be warned, they can be overridden at upload time!

# name of web to upload to
$build->{UPLOADTARGETWEB} = 'Extensions';
# Full URL of pub directory
$build->{UPLOADTARGETPUB} = 'http://foswiki.org/pub';
# Full URL of bin directory
$build->{UPLOADTARGETSCRIPT} = 'http://foswiki.org/bin';
# Script extension
$build->{UPLOADTARGETSUFFIX} = '';

# Build the target on the command line, or the default target
$build->build($build->{target});

0 comments on commit 5a7d422

Please sign in to comment.