Problem/Motivation

When you have a lot of translated strings, it would be helpful to drill down by context, to allow a user to only see specific groups of strings.

Proposed resolution

Drupal allows any reference to the t() function to provide an optional context as a parameter (see Translation string sharing and context).

For example something like this:

// PHP code
t('May', array(), array('context' => 'Long month name');
\Drupal::translation()->formatPlural($count, '1 something',
  '@count somethings', array(), array('context' => 'My context'));

I propose adding the ability to filter based on a list of defined contexts in the system.

Remaining tasks

  1. Write Functionality
  2. Update Tests
  3. Add Screenshot

User interface changes

  1. Adds a "context" filter to the locale source plugin UI.
  2. Adds a "context" column to the local source plugin table results.

API changes

None

Data model changes

None

Comments

WidgetsBurritos created an issue. See original summary.

WidgetsBurritos’s picture

Assigned: Unassigned » WidgetsBurritos

I am presently working on a patch to introduce this functionality.

WidgetsBurritos’s picture

Status: Active » Needs review
StatusFileSize
new4.01 KB

Here is an initial patch with what I'm proposing

WidgetsBurritos’s picture

StatusFileSize
new5.09 KB
new1.73 KB

I actually updated my previous patch a little bit, to also show context in the table itself, as it helps provide clarity between different instances of the same string.

WidgetsBurritos’s picture

Assigned: WidgetsBurritos » Unassigned
WidgetsBurritos’s picture

Issue summary: View changes

Updating the issue summary. As these are merely UI changes, not sure there's much to test, unless we want some browser test cases, but adding that to the list just in case.

Status: Needs review » Needs work

The last submitted patch, 4: 2978454--context-filter-locale-source--4.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

WidgetsBurritos’s picture

Status: Needs work » Needs review
StatusFileSize
new2.19 KB
new7.39 KB

Well those test failures answered my question about UI test cases. So I've gone ahead and updated the tests to reflect both that context is visible in the table, and that filtering by context works.

WidgetsBurritos’s picture

Issue summary: View changes
StatusFileSize
new348.25 KB

Here is a screenshot of what this might look like:
Context filter example

berdir’s picture

Status: Needs review » Fixed

Nice work, nothing to complain about except the use of $_GET, but lets clean up all usages of that at once in a separate issue. Patches for that very welcome :)

WidgetsBurritos’s picture

For sure about those $_GET references. I just didn’t want to break the established convention here. When I get a chance I’ll be happy to help clean some of that up

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.