Skip to content
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

unified imperial, metric strings (removes need for %s separate.) #204

Merged
merged 1 commit into from
May 9, 2022
Merged

unified imperial, metric strings (removes need for %s separate.) #204

merged 1 commit into from
May 9, 2022

Conversation

marc-medley
Copy link
Member

See Issue #201 for discussion. The normalized update XML file are linked. The needed java modified is mentioned here but not implemented.

In the string.xml files, the only content structure change should be the string-array food_info_serving_sizes_* elements. Other string.xml changes should only be formatting into a common order to support comparison via a common text compare tools.

Existing release food_info_serving_sizes_* content structure:

<string-array name="food_info_serving_sizes_other_fruits">
    <item>%s1 medium-sized fruit</item>
    <item>1%s cut-up fruit</item>
    <item>%s dried fruit</item>
</string-array>
<string-array name="food_info_serving_sizes_other_fruits_imperial">
    <item />
    <item> cup</item>
    <item>¼ cup</item>
</string-array>
<string-array name="food_info_serving_sizes_other_fruits_metric">
    <item />
    <item>20 g</item>
    <item>40 g</item>
</string-array>

Proposed food_info_serving_sizes_* content structure is shown below. Fewer elements. Easer to read. One-to-one correspondence to what the translator sees in a spreadsheet row.

<string-array name="food_info_serving_sizes_other_fruits_imperial">
    <item>1 medium-sized fruit</item>
    <item>1 cup cut-up fruit</item>
    <item>¼ cup dried fruit</item>
</string-array>
<string-array name="food_info_serving_sizes_other_fruits_metric">
    <item>1 medium-sized fruit</item>
    <item>120 g cut-up fruit</item>
    <item>40 g dried fruit</item>
</string-array>

The affected *.java would appear to be:

private static int getServingSizesResourceId(final Context context,
                                             final String idSuffix) {
    return context.getResources().getIdentifier(
            "food_info_serving_sizes_" + idSuffix.toLowerCase(),
            "array",
            context.getApplicationInfo().packageName);
}

private static int getServingSizesResourceId(final Context context,
                                             final String foodName,
                                             @Units.Interface final int unitType) {
    return getServingSizesResourceId(context,
            foodName + (unitType == Units.IMPERIAL ? "_imperial" : "_metric"));
}

private static void initServingSizesForFood(final Context context, final String foodIdName) {
    // ... SNIP ...  
   
    // Dynamically load the string-arrays for food.
    // The naming convention below must be followed:
    //      food_info_serving_sizes_<formattedFoodIdName>
    //      food_info_serving_sizes_<formattedFoodIdName>_imperial
    //      food_info_serving_sizes_<formattedFoodIdName>_metric
    String[] servingSizeTexts = res.getStringArray(getServingSizesResourceId(context, formattedFoodIdName));
    String[] imperialServingSizes = res.getStringArray(getServingSizesResourceId(context, formattedFoodIdName, Units.IMPERIAL));
    String[] metricServingSizes = res.getStringArray(getServingSizesResourceId(context, formattedFoodIdName, Units.METRIC));

    final List<String> imperial = new ArrayList<>();
    final List<String> metric = new ArrayList<>();

    for (int i = 0; i < servingSizeTexts.length; i++) {
        imperial.add(String.format(locale, servingSizeTexts[i], imperialServingSizes[i]));
        metric.add(String.format(locale, servingSizeTexts[i], metricServingSizes[i]));
    }

    servingSizesImperial.put(foodIdName, imperial);
    servingSizesMetric.put(foodIdName, metric);

    //  ... SNIP ...
}

@slavick slavick merged commit c0ce7f7 into nutritionfactsorg:unified-descriptions May 9, 2022
slavick added a commit that referenced this pull request Aug 14, 2022
* unified imperial, metric strings (removes need for %s) (#204)

see #201

* Implement change to read full serving size strings instead of building them

* russian update, escaped quotes, %s simplification  (#205)

* russian update

* xml fixes: `\\'` to `\'`, `\ N` to `\n\n`

* escaped double quotes `\"`

* fixed "about_text_lines" mapping. also some misc update (fractions)

* some Italian updates. French: l\\'application --> l\'application

* Update versionCode and versionName

* Remove redundant label

* Add try/catch for exception that has been observed

* Remove unpopular translations

* Update strings

* Change createWeightsIfDoesNotExist to return boolean (indicating weights saved) instead of the unused Weights object

* Remove unused code

* Revert "Remove unpopular translations"

This reverts commit a6b9c9c.

* Update strings

* Update versionCode

* Update Spanish translation

* Update versionCode and versionName

* Update Spanish (#206)

Co-authored-by: --marc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants