New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to the language editor #5037

Merged
merged 37 commits into from Oct 11, 2018

Conversation

Projects
None yet
4 participants
@Sesquipedalian
Member

Sesquipedalian commented Oct 6, 2018

  1. Fixes #4855
  2. Fixes #4856
  3. Adds language editor support for literal string keys in $txt arrays.
  4. Adds language editor support for $txt['foo']['bar'] = 'baz'; syntax.
  5. Adds support for adding and removing values inside $txt arrays.
  6. Gracefully handles trailing comments and whitespace in language files.
  7. Tightens up some logic and eliminates some code duplication.
  8. Handles $txt arrays as proper arrays on HTML form.
  9. Makes some minor improvements to the language editor UI.
  10. Adds native_name and lang_recaptcha to the primary settings of a language.
  11. Allows mods to add additional string types via integration hook.
  12. Fixes various unreported bugs discovered during testing.

Sesquipedalian added some commits Oct 4, 2018

Fixes an undefined index error when editing arrays of strings
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Always uses Unix line endings when editing language files
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Comments out original string arrays when saving changes to them
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Implements a more robust method to process $txt entry arrays
Fixes #4855

Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Allows hooks to add additional string types
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Reorganizes some logic in order to eliminate code duplication
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Handles trailing comments gracefully
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Abstracts the handling of primary language settings
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Ensures trailing whitespace is not included in the full entry
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Handle $txt arrays as proper arrays on HTML form (Death to kludges!)
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Adds a link to Google's reCAPTCHA language documentation
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Adds language editor support for string keys in $txt arrays
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Uses the right value to decide whether to edit as a string or an array
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Adds language editor support for $txt['foo']['bar'] = 'baz';
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Adds support for removing elements from a $txt array
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Allows adding new strings like $txt['foo']['bar'] = 'baz';
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Allows adding new elements to existing $txt arrays
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Uses a nice little variable instead of doing things the hard way
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Fixes a bug when dealing with strings containing newlines
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Sets a reasonable maximum number of rows for language editor textareas
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Fixes a bug with saving multiline strings
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Implements a more reliable method for finding complete $txt variables
Fixes #4856

Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Sets 'u' flag on preg_match() based on $context['utf8']
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Shows the "Add another item" (if allowed) for empty groups of strings
Signed-off-by: Jon Stovell <jonstovell@gmail.com>

@Sesquipedalian Sesquipedalian added this to the RC 1 milestone Oct 6, 2018

@Sesquipedalian

This comment has been minimized.

Show comment
Hide comment
@Sesquipedalian

Sesquipedalian Oct 6, 2018

Member

To test, try pasting this into Modifications.english.php and then messing around with the values in the language editor:

$txt['mline'] = 'This has multiple lines in it.
It is followed by int_elements[0].
This line ends in a semicolon;
Does this line show up too?';

$txt['int_elements'][0] = 'foo';
$txt['int_elements'][1] = 'bar';
$txt['int_elements'][2] = 'baz';

$txt['string_elements']['a'] = 'foo';
$txt['string_elements']['b'] = 'bar';
$txt['string_elements']['c'] = 'baz';

$txt['string_key_array'] = array('a' => 'foo', 'b' => 'bar', 'c' => 'baz');

$txt['int_key_array'] = array(1 => 'foo', 'bar', 12 => 'baz');

$txt['simple_array'] = array('foo', 'bar', 'baz');

$txt['simple_string_foo'] = 'foo';
$txt['simple_string_bar'] = 'bar';
$txt['simple_string_baz'] = 'baz';
Member

Sesquipedalian commented Oct 6, 2018

To test, try pasting this into Modifications.english.php and then messing around with the values in the language editor:

$txt['mline'] = 'This has multiple lines in it.
It is followed by int_elements[0].
This line ends in a semicolon;
Does this line show up too?';

$txt['int_elements'][0] = 'foo';
$txt['int_elements'][1] = 'bar';
$txt['int_elements'][2] = 'baz';

$txt['string_elements']['a'] = 'foo';
$txt['string_elements']['b'] = 'bar';
$txt['string_elements']['c'] = 'baz';

$txt['string_key_array'] = array('a' => 'foo', 'b' => 'bar', 'c' => 'baz');

$txt['int_key_array'] = array(1 => 'foo', 'bar', 12 => 'baz');

$txt['simple_array'] = array('foo', 'bar', 'baz');

$txt['simple_string_foo'] = 'foo';
$txt['simple_string_bar'] = 'bar';
$txt['simple_string_baz'] = 'baz';

Sesquipedalian added some commits Oct 6, 2018

Correctly handles replacements for native_name setting
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Adds a few comments and cosmetic changes to the code
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Adds $helptxt for primary language settings
Signed-off-by: Jon Stovell <jonstovell@gmail.com>

Sesquipedalian added some commits Oct 6, 2018

Makes sure we process the last $blob
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Uses file_get_contents() and preg_split() to extract $txt variables
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
@Sesquipedalian

This comment has been minimized.

Show comment
Hide comment
@Sesquipedalian

Sesquipedalian Oct 8, 2018

Member

I decided to change again the method for extracting the individual $txt variables from the file. Even though the method I was using as of 095e277 seems to have worked well, using file_get_contents() and preg_split() to do the job (1) is much simpler, (2) eliminates any possibility of problems that could arise from processing lines one at a time (the root cause of most of the bugs), and (3) performs fewer total preg_* operations to do the job.

Member

Sesquipedalian commented Oct 8, 2018

I decided to change again the method for extracting the individual $txt variables from the file. Even though the method I was using as of 095e277 seems to have worked well, using file_get_contents() and preg_split() to do the job (1) is much simpler, (2) eliminates any possibility of problems that could arise from processing lines one at a time (the root cause of most of the bugs), and (3) performs fewer total preg_* operations to do the job.

Sesquipedalian added some commits Oct 8, 2018

Strips off trailing comment lines when extracting $txt variables
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Preserves trailing inline comments when saving new string values
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
@Sesquipedalian

This comment has been minimized.

Show comment
Hide comment
@Sesquipedalian

Sesquipedalian Oct 8, 2018

Member

Unless anyone finds any bugs, this is done.

Member

Sesquipedalian commented Oct 8, 2018

Unless anyone finds any bugs, this is done.

@jdarwood007

This comment has been minimized.

Show comment
Hide comment
@jdarwood007

jdarwood007 Oct 8, 2018

Member

If the file is empty, doesn't seem to let you add entries.

$ cat Themes/default/languages/Modifications.english.php

<?php
// Version: 2.1 Beta 4; Modifications

?>

Try to add a entry and it saves but nothing is added.

Member

jdarwood007 commented Oct 8, 2018

If the file is empty, doesn't seem to let you add entries.

$ cat Themes/default/languages/Modifications.english.php

<?php
// Version: 2.1 Beta 4; Modifications

?>

Try to add a entry and it saves but nothing is added.

Sesquipedalian added some commits Oct 9, 2018

Handles arbitrary whitespace at end of file when adding new strings
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Allows admin to add strings to ThemeStrings.*.php, not Themes.*.php
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Adds some UI niceties to the language editor
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
@Sesquipedalian

This comment has been minimized.

Show comment
Hide comment
@Sesquipedalian

Sesquipedalian Oct 9, 2018

Member

That should be fixed now, @jdarwood007

Member

Sesquipedalian commented Oct 9, 2018

That should be fixed now, @jdarwood007

Sesquipedalian added some commits Oct 9, 2018

Adds a conditional check when deciding where to redirect after saving
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Fixes typo
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Improves discoverability of language editor (adds button to main page)
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
@jdarwood007

This comment has been minimized.

Show comment
Hide comment
@jdarwood007

jdarwood007 Oct 9, 2018

Member

Looks good to me now. Not sure if for a commit of this size if we should have another reviewer.

Member

jdarwood007 commented Oct 9, 2018

Looks good to me now. Not sure if for a commit of this size if we should have another reviewer.

@Sesquipedalian Sesquipedalian merged commit 2b43e54 into SimpleMachines:release-2.1 Oct 11, 2018

2 checks passed

Scrutinizer 10 new issues
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@Sesquipedalian Sesquipedalian deleted the Sesquipedalian:langedit-arrays branch Oct 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment