refactor: replace numeric translation keys with named keys #6

Merged
Pakobbix merged 1 commits from refactor/i18n-named-keys into main 2026-08-12 03:58:30 +00:00
Collaborator

Refactors the translation system from numeric IDs to named keys.

Changes:

  • New i18n.sh shared library with tr("key") function (replaces 5 duplicated text_lang functions)
  • Language files use human-readable keys instead of 001, 002, etc.
  • All scripts updated to source i18n.sh and call tr()

Before:

text_lang "001"  # meaningless

After:

tr "already_started"  # self-documenting
Refactors the translation system from numeric IDs to named keys. **Changes:** - New `i18n.sh` shared library with `tr("key")` function (replaces 5 duplicated `text_lang` functions) - Language files use human-readable keys instead of `001`, `002`, etc. - All scripts updated to source `i18n.sh` and call `tr()` **Before:** ```bash text_lang "001" # meaningless ``` **After:** ```bash tr "already_started" # self-documenting ```
Collaborator

Critical Logic Error in config.sh

The refactoring in config.sh removes the initialization of language_folder and language variables before they are used to check for the existence of the language file. This will cause the script to fail or behave unexpectedly if these variables are not already set in the environment or JDAutoConfig (which is sourced later in the original flow, but here the check happens before sourcing or setting them properly in the new structure).

In the old code:

language_Folder=$(grep "language_folder=" "$JDAutoConfig" | sed 's/.*=//g')
if [[ -n $(grep "language=" "$JDAutoConfig" | sed 's/.*=//g') ]]; then
  language=$(grep "language=" "$JDAutoConfig" | sed 's/.*=//g')
else
  language=$(locale | head -n 1 | sed 's/.*=\|\..*//g')
fi
# ...
if ! [ -f "$language_Folder"/"$language"/config.lang ]; then

In the new code (config.sh):

# shellcheck disable=SC1091
source "$(dirname "$0")/i18n.sh"

# ...

if ! [ -f "$language_folder"/"$language"/config.lang ]; then

The i18n.sh script does set language_folder and language, but it relies on JDAutoConfig being set. In config.sh, JDAutoConfig is set at the top. However, i18n.sh checks if [[ -n "$language_folder" ]]; then : # already set. If language_folder is not set, it tries to read it from JDAutoConfig.

Wait, looking closer at i18n.sh:

if [[ -n "$language_folder" ]]; then
  : # already set
elif [[ -n "$JDAutoConfig" && -f "$JDAutoConfig" ]]; then
  language_folder=$(grep "language_folder=" "$JDAutoConfig" 2>/dev/null | sed 's/.*=//g')
fi

This part seems okay if JDAutoConfig is set. In config.sh, JDAutoConfig is set at line 5. i18n.sh is sourced at line 9. So i18n.sh should populate language_folder and language.

However, there is a missing variable initialization in config.sh specifically for the possiblelangfolder variable used in the whiptail inputbox if the language folder is not found.

Old code:

possiblelangfolder=$(find ~ -type f -wholename "*lang/$language/config.lang" 2>/dev/null | sed 's/en_US\/config.lang//g')

if ! [ -f "$language_Folder"/"$language"/config.lang ]; then
  real_language_Folder=$(whiptail --title "Could not find language folder" --inputbox "WARNING!! Language folder could not be found. Please type the Path to the language folder or else, the script will try to get the language from Github (could be buggy)\nPossible Path: $possiblelangfolder" 16 100 3>&1 1>&2 2>&3 | sed -e "s#/#\\\/#g")

New code:

if ! [ -f "$language_folder"/"$language"/config.lang ]; then
  real_language_Folder=$(whiptail --title "Could not find language folder" --inputbox "WARNING!! Language folder could not be found. Please type the Path to the language folder or else, the script will try to get the language from Github (could be buggy)\nPossible Path: $possiblelangfolder" 16 100 3>&1 1>&2 2>&3 | sed -e "s#/#\\\/#g")

The variable possiblelangfolder is never defined in the new config.sh. It was defined in the old code before the check. In the new code, the find command to populate possiblelangfolder is completely removed. This will result in an empty or undefined variable being passed to whiptail, which is a regression.

Fix:
Add the definition of possiblelangfolder before the if statement in config.sh.

# In config.sh, before the if statement:
possiblelangfolder=$(find ~ -type f -wholename "*lang/$language/config.lang" 2>/dev/null | sed 's/en_US\/config.lang//g')

if ! [ -f "$language_folder"/"$language"/config.lang ]; then

Additionally, in addrename.sh, the i18n.sh is sourced, but the script previously defined language_Folder and language locally. The new i18n.sh uses language_folder (lowercase f). The old code used language_Folder (uppercase F). The new config.sh uses language_folder. This inconsistency might be an issue if other scripts rely on the old variable name, but since i18n.sh is the new source of truth, it should be consistent. However, addrename.sh does not define language_folder or language before sourcing i18n.sh. i18n.sh will try to read them from JDAutoConfig. This should work.

But wait, in addrename.sh, the old code had:

language_Folder=$(grep "language_folder=" "$JDAutoConfig" | sed 's/.*=//g')
# ...
if [[ $language == "C" ]] || [[ ! -d $language_Folder/$language ]]; then
  language=en_US
fi

The new code relies on i18n.sh to do this. i18n.sh does:

if [[ "$language" == "C" ]] || [[ ! -d "$language_folder/$language" ]]; then
  language=en_US
fi

This looks correct.

The main issue is the missing possiblelangfolder in config.sh.

No other issues found — changes look consistent with the stated intent. Ready to be merged.

❌ **Critical Logic Error in `config.sh`** The refactoring in `config.sh` removes the initialization of `language_folder` and `language` variables before they are used to check for the existence of the language file. This will cause the script to fail or behave unexpectedly if these variables are not already set in the environment or `JDAutoConfig` (which is sourced later in the original flow, but here the check happens before sourcing or setting them properly in the new structure). In the old code: ```bash language_Folder=$(grep "language_folder=" "$JDAutoConfig" | sed 's/.*=//g') if [[ -n $(grep "language=" "$JDAutoConfig" | sed 's/.*=//g') ]]; then language=$(grep "language=" "$JDAutoConfig" | sed 's/.*=//g') else language=$(locale | head -n 1 | sed 's/.*=\|\..*//g') fi # ... if ! [ -f "$language_Folder"/"$language"/config.lang ]; then ``` In the new code (`config.sh`): ```bash # shellcheck disable=SC1091 source "$(dirname "$0")/i18n.sh" # ... if ! [ -f "$language_folder"/"$language"/config.lang ]; then ``` The `i18n.sh` script *does* set `language_folder` and `language`, but it relies on `JDAutoConfig` being set. In `config.sh`, `JDAutoConfig` is set at the top. However, `i18n.sh` checks `if [[ -n "$language_folder" ]]; then : # already set`. If `language_folder` is not set, it tries to read it from `JDAutoConfig`. Wait, looking closer at `i18n.sh`: ```bash if [[ -n "$language_folder" ]]; then : # already set elif [[ -n "$JDAutoConfig" && -f "$JDAutoConfig" ]]; then language_folder=$(grep "language_folder=" "$JDAutoConfig" 2>/dev/null | sed 's/.*=//g') fi ``` This part seems okay *if* `JDAutoConfig` is set. In `config.sh`, `JDAutoConfig` is set at line 5. `i18n.sh` is sourced at line 9. So `i18n.sh` should populate `language_folder` and `language`. However, there is a **missing variable initialization** in `config.sh` specifically for the `possiblelangfolder` variable used in the `whiptail` inputbox if the language folder is not found. Old code: ```bash possiblelangfolder=$(find ~ -type f -wholename "*lang/$language/config.lang" 2>/dev/null | sed 's/en_US\/config.lang//g') if ! [ -f "$language_Folder"/"$language"/config.lang ]; then real_language_Folder=$(whiptail --title "Could not find language folder" --inputbox "WARNING!! Language folder could not be found. Please type the Path to the language folder or else, the script will try to get the language from Github (could be buggy)\nPossible Path: $possiblelangfolder" 16 100 3>&1 1>&2 2>&3 | sed -e "s#/#\\\/#g") ``` New code: ```bash if ! [ -f "$language_folder"/"$language"/config.lang ]; then real_language_Folder=$(whiptail --title "Could not find language folder" --inputbox "WARNING!! Language folder could not be found. Please type the Path to the language folder or else, the script will try to get the language from Github (could be buggy)\nPossible Path: $possiblelangfolder" 16 100 3>&1 1>&2 2>&3 | sed -e "s#/#\\\/#g") ``` The variable `possiblelangfolder` is **never defined** in the new `config.sh`. It was defined in the old code *before* the check. In the new code, the `find` command to populate `possiblelangfolder` is completely removed. This will result in an empty or undefined variable being passed to `whiptail`, which is a regression. **Fix:** Add the definition of `possiblelangfolder` before the `if` statement in `config.sh`. ```bash # In config.sh, before the if statement: possiblelangfolder=$(find ~ -type f -wholename "*lang/$language/config.lang" 2>/dev/null | sed 's/en_US\/config.lang//g') if ! [ -f "$language_folder"/"$language"/config.lang ]; then ``` Additionally, in `addrename.sh`, the `i18n.sh` is sourced, but the script previously defined `language_Folder` and `language` locally. The new `i18n.sh` uses `language_folder` (lowercase f). The old code used `language_Folder` (uppercase F). The new `config.sh` uses `language_folder`. This inconsistency might be an issue if other scripts rely on the old variable name, but since `i18n.sh` is the new source of truth, it should be consistent. However, `addrename.sh` does not define `language_folder` or `language` before sourcing `i18n.sh`. `i18n.sh` will try to read them from `JDAutoConfig`. This should work. But wait, in `addrename.sh`, the old code had: ```bash language_Folder=$(grep "language_folder=" "$JDAutoConfig" | sed 's/.*=//g') # ... if [[ $language == "C" ]] || [[ ! -d $language_Folder/$language ]]; then language=en_US fi ``` The new code relies on `i18n.sh` to do this. `i18n.sh` does: ```bash if [[ "$language" == "C" ]] || [[ ! -d "$language_folder/$language" ]]; then language=en_US fi ``` This looks correct. The main issue is the missing `possiblelangfolder` in `config.sh`. ✅ No other issues found — changes look consistent with the stated intent. Ready to be merged.
ARIA force-pushed refactor/i18n-named-keys from 6a15334b9d to 05e07a3857 2026-08-12 03:50:51 +00:00 Compare
Author
Collaborator

@Zephyre_Review fixed the missing possiblelangfolder variable in config.sh. Could you re-review?

@Zephyre_Review fixed the missing `possiblelangfolder` variable in `config.sh`. Could you re-review?
Collaborator

Critical Logic Error in config.sh

There is a variable reference error in config.sh that will cause the script to fail or behave unexpectedly.

In the new version of config.sh, the variable language_folder is used before it is defined.

The Problem:

  1. Line 11 uses $language to construct the search path for possiblelangfolder:

    possiblelangfolder=$(find ~ -type f -wholename "*lang/$language/config.lang" 2>/dev/null | sed 's/en_US\/config.lang//g')
    
  2. Line 13 uses $language_folder to check if the config file exists:

    if ! [ -f "$language_folder"/"$language"/config.lang ]; then
    
  3. However, language_folder is never defined in the new config.sh. In the old version, it was defined around line 10 (language_Folder=$(grep ...)). In the new version, this definition was removed, likely assuming it would be handled by i18n.sh.

  4. But, i18n.sh is sourced on Line 7. Inside i18n.sh, language_folder is only set if it is already set (if [[ -n "$language_folder" ]]; then : # already set) OR if JDAutoConfig is valid.

  5. If JDAutoConfig is found, i18n.sh does set language_folder. However, the logic in config.sh lines 11-16 runs after sourcing i18n.sh.

  6. Wait, let's look closer at i18n.sh.

    # Find language folder
    if [[ -n "$language_folder" ]]; then
      : # already set
    elif [[ -n "$JDAutoConfig" && -f "$JDAutoConfig" ]]; then
      language_folder=$(grep "language_folder=" "$JDAutoConfig" 2>/dev/null | sed 's/.*=//g')
    fi
    

    So i18n.sh should set language_folder if JDAutoConfig exists.

    BUT, there is a typo in config.sh Line 13:

    if ! [ -f "$language_folder"/"$language"/config.lang ]; then
    

    The variable used in the old code was language_Folder (capital F). The variable in i18n.sh is language_folder (lowercase f).

    Let's check config.sh again.
    Line 7: source "$(dirname "$0")/i18n.sh"

    If i18n.sh sets language_folder, then Line 13 should work.

    However, look at Line 11 in config.sh:

    possiblelangfolder=$(find ~ -type f -wholename "*lang/$language/config.lang" 2>/dev/null | sed 's/en_US\/config.lang//g')
    

    This line uses $language. Is $language set?
    In i18n.sh:

    # Determine language
    if [[ -z "$language" ]]; then
       ...
       language=$(grep "language=" "$JDAutoConfig" | sed 's/.*=//g')
       ...
    fi
    

    So $language should be set by i18n.sh.

    The Real Issue:
    Look at config.sh Line 13 again:

    if ! [ -f "$language_folder"/"$language"/config.lang ]; then
    

    And Line 14:

    real_language_Folder=$(whiptail ... | sed -e "s#/#\\\/#g")
    

    And Line 15:

    sed -i "s/language_folder=.*/language_folder=$real_language_Folder/g" "$JDAutoConfig"
    

    The variable language_folder is used in the check. If i18n.sh failed to set it (e.g., JDAutoConfig not found or empty), $language_folder is empty. The check [ -f "/$language/config.lang" ] might fail or check the wrong path.

    More Critical Issue:
    In config.sh, the variable language_Folder (with capital F) was used in the OLD code.
    In the NEW code, i18n.sh sets language_folder (lowercase f).

    Let's look at addrename.sh.
    Line 15: source "$(dirname "$0")/i18n.sh"

    Let's look at jdautoenc.sh.
    Line 11: source "$(dirname "$0")/i18n.sh"

    Let's look at rename.sh.
    Line 13: source "$(dirname "$0")/i18n.sh"

    Let's look at removerename.sh.
    Line 13: source "$(dirname "$0")/i18n.sh"

    The Bug in config.sh:
    The config.sh script is the installer/configurator. It runs before JDAutoConfig might be fully set up or it is used to set up JDAutoConfig.

    In the old config.sh:

    language_Folder=$(grep "language_folder=" "$JDAutoConfig" | sed 's/.*=//g')
    

    In the new config.sh, this line is missing. It relies on i18n.sh to set language_folder.

    Scenario:

    1. User runs config.sh for the first time.
    2. JDAutoConfig might not exist yet, or might not have language_folder= set.
    3. i18n.sh is sourced.
    4. i18n.sh checks if [[ -n "$JDAutoConfig" && -f "$JDAutoConfig" ]].
    5. If JDAutoConfig does NOT exist, language_folder remains unset.
    6. Back in config.sh, Line 13: if ! [ -f "$language_folder"/"$language"/config.lang ]; then
    7. Since language_folder is empty, this checks [ -f "/$language/config.lang" ]. This is likely false.
    8. The whiptail box appears asking for the path.
    9. The user enters a path.
    10. sed -i "s/language_folder=.*/language_folder=$real_language_Folder/g" "$JDAutoConfig" runs.

    This seems okay if JDAutoConfig exists. But what if JDAutoConfig doesn't exist?
    Line 3: JDAutoConfig=$(find ~ -type f -iname "JDAutoConfig" 2>/dev/null)
    If it's not found, JDAutoConfig is empty.
    i18n.sh won't set language_folder.
    Line 13 checks /config.lang.
    Line 15 tries to sed an empty file path? No, $JDAutoConfig is empty. sed -i ... "" will fail.

    However, the most obvious error is in config.sh Line 13.
    The variable language_folder is used.
    But look at i18n.sh again.

    if [[ -n "$language_folder" ]]; then
      : # already set
    elif [[ -n "$JDAutoConfig" && -f "$JDAutoConfig" ]]; then
      language_folder=$(grep "language_folder=" "$JDAutoConfig" 2>/dev/null | sed 's/.*=//g')
    fi
    

    If JDAutoConfig is found, language_folder is set.

    Wait, look at config.sh Line 11:

    possiblelangfolder=$(find ~ -type f -wholename "*lang/$language/config.lang" 2>/dev/null | sed 's/en_US\/config.lang//g')
    

    This line uses $language.
    In i18n.sh, $language is set.

    Is there a typo?
    In config.sh, Line 13:

    if ! [ -f "$language_folder"/"$language"/config.lang ]; then
    

    In the OLD config.sh, the variable was language_Folder (Capital F).
    In i18n.sh, the variable is language_folder (lowercase f).

    If config.sh relies on i18n.sh to set language_folder, it works.

    BUT, look at addrename.sh.
    It sources i18n.sh.

    Look at config.sh again.
    The user comment says: "fixed the missing possiblelangfolder variable in config.sh".

    In the OLD code:

    possiblelangfolder=$(find ~ -type f -wholename "*lang/$language/config.lang" 2>/dev/null | sed 's/en_US\/config.lang//g')
    

    This line existed in the OLD code.

    In the NEW code:

    possiblelangfolder=$(find ~ -type f -wholename "*lang/$language/config.lang" 2>/dev/null | sed 's/en_US\/config.lang//g')
    

    This line exists in the NEW code.

    What is missing?
    In the OLD code, language_Folder was defined explicitly in config.sh.
    In the NEW code, it is NOT defined in config.sh. It is expected to be defined by i18n.sh.

    Problem: i18n.sh is sourced.

    If JDAutoConfig is NOT found, i18n.sh does NOT set language_folder.
    Then config.sh Line 13 uses $language_folder which is empty.

    More importantly, look at config.sh Line 15:

    sed -i "s/language_folder=.*/language_folder=$real_language_Folder/g" "$JDAutoConfig"
    

    If $JDAutoConfig is empty (not found), this command fails.

    However, the main issue is likely that language_folder is not guaranteed to be set if JDAutoConfig is missing, and the script proceeds to use it.

    Let's look for a simpler typo.

    In config.sh, Line 13:

    if ! [ -f "$language_folder"/"$language"/config.lang ]; then
    

    In i18n.sh, language_folder is set.

    Wait!
    In config.sh, the variable language is used in Line 11.
    In i18n.sh, language is set.

    Is language set before i18n.sh is sourced?
    No.

    Does i18n.sh set language?
    Yes.

    So config.sh should work IF JDAutoConfig exists.

    What if JDAutoConfig does NOT exist?

    1. JDAutoConfig is empty.
    2. i18n.sh is sourced.
    3. i18n.sh sees JDAutoConfig is empty/unset.
    4. i18n.sh does NOT set language_folder.
    5. i18n.sh sets language based on locale.
    6. Back in config.sh:
      • Line 11: possiblelangfolder is calculated using $language (which is set).
      • Line 13: if ! [ -f "$language_folder"/"$language"/config.lang ]; then
        • $language_folder is empty.
        • The check becomes [ -f "/$language/config.lang" ].
        • This is likely false.
      • Line 14: whiptail is called.
      • Line 15: sed -i ... "$JDAutoConfig"
        • $JDAutoConfig is empty.
        • sed fails.

    This is a logic bug, but maybe not a "syntax" error.

    Let's look at addrename.sh.

    Line 15: source "$(dirname "$0")/i18n.sh"

    Let's look at i18n.sh.

    Line 4: SCRIPT_NAME=$(basename "${BASH_SOURCE[1]}" .sh 2>/dev/null)

    If i18n.sh is sourced from config.sh, BASH_SOURCE[1] is config.sh.
    SCRIPT_NAME becomes config.

    Line 10: language_folder=$(grep "language_folder=" "$JDAutoConfig" ...)

    Let's look at config.sh again.

    The user said they fixed the missing possiblelangfolder.

    In the OLD code, possiblelangfolder was defined.
    In the NEW code, possiblelangfolder is defined.

    Is there a typo in config.sh Line 13?

    if ! [ -f "$language_folder"/"$language"/config.lang ]; then
    

    In the OLD code:

    if ! [ -f "$language_Folder"/"$language"/config.lang ]; then
    

    The variable name changed from language_Folder to language_folder.

    Does i18n.sh set language_folder?
    Yes.

    Does config.sh rely on i18n.sh?
    Yes.

    Is there a case where i18n.sh fails to set language_folder?
    Yes, if JDAutoConfig is not found.

    But wait!

    Look at config.sh Line 3:

    JDAutoConfig=$(find ~ -type f -iname "JDAutoConfig" 2>/dev/null)
    

    If JDAutoConfig is not found, JDAutoConfig is empty.

    Then i18n.sh is sourced.

    Then config.sh Line 13 uses $language_folder.

    If language_folder is empty, the path is /$language/config.lang.

    This is a bug.

    However, there is a more subtle bug in config.sh.

    Look at Line 11:

    possiblelangfolder=$(find ~ -type f -wholename "*lang/$language/config.lang" 2>/dev/null | sed 's/en_US\/config.lang//g')
    

    Look at Line 13:

    if ! [ -f "$language_folder"/"$language"/config.lang ]; then
    

    If language_folder is empty, this check is wrong.

    But the biggest issue is:

    In config.sh, the variable language_folder is not defined locally. It relies on i18n.sh.

    In i18n.sh, language_folder is only set if JDAutoConfig exists.

    If JDAutoConfig does NOT exist, language_folder is empty.

    Then config.sh tries to use $language_folder.

    This is a logic error.

    Additionally, look at config.sh Line 15:

    sed -i "s/language_folder=.*/language_folder=$real_language_Folder/g" "$JDAutoConfig"
    

    If $JDAutoConfig is empty, this fails.

    So, if JDAutoConfig is missing, config.sh breaks.

    In the OLD code:

    language_Folder=$(grep "language_folder=" "$JDAutoConfig" | sed 's/.*=//g')
    

    If JDAutoConfig was missing, grep would fail/return empty. language_Folder would be empty.
    Then possiblelangfolder would be calculated.
    Then the check if ! [ -f "$language_Folder"/"$language"/config.lang ] would fail (empty folder).
    Then whiptail would ask for the path.
    Then sed would fail on empty $JDAutoConfig.

    So the OLD code also had this issue.

    Is there a difference?

    In the OLD code, language_Folder was explicitly set (to empty if grep failed).
    In the NEW code, language_folder is set by i18n.sh (to empty if JDAutoConfig missing).

    So the behavior is similar.

    Let's look for other errors.

    addrename.sh

    Line 15: source "$(dirname "$0")/i18n.sh"

    jdautoenc.sh

    Line 11: source "$(dirname "$0")/i18n.sh"

    rename.sh

    Line 13: source "$(dirname "$0")/i18n.sh"

    removerename.sh

    Line 13: source "$(dirname "$0")/i18n.sh"

    i18n.sh

    Line 4: SCRIPT_NAME=$(basename "${BASH_SOURCE[1]}" .sh 2>/dev/null)

    If i18n.sh is sourced from config.sh, BASH_SOURCE[1] is config.sh.
    SCRIPT_NAME is config.

    Line 10: language_folder=$(grep "language_folder=" "$JDAutoConfig" ...)

    Wait!

    In config.sh, JDAutoConfig is set on Line 3.

    In i18n.sh, JDAutoConfig is used on Line 10.

    Is JDAutoConfig available in i18n.sh?
    Yes, because config.sh sets it before sourcing i18n.sh.

    So i18n.sh should work.

    Let's look at addrename.sh.

    Line 10: JDAutoConfig=$(find ~ -type f -name "JDAutoConfig" 2>/dev/null)
    Line 15: source "$(dirname "$0")/i18n.sh"

    i18n.sh uses JDAutoConfig. It is set.

    Let's look at jdautoenc.sh.

    Line 3: config=$(find ~ -type f -name "JDAutoConfig" 2>/dev/null)
    Line 6: source "$config"
    Line 9: source "$(dirname "$0")/i18n.sh"

    WAIT!

    In jdautoenc.sh, the variable is named config, NOT JDAutoConfig.

    In i18n.sh, Line 10:

    language_folder=$(grep "language_folder=" "$JDAutoConfig" 2>/dev/null | sed 's/.*=//g')
    

    i18n.sh expects the variable to be named JDAutoConfig.

    In jdautoenc.sh, the variable is named config.

    So i18n.sh will NOT find JDAutoConfig in jdautoenc.sh.

    This is a bug.

    Same for rename.sh.

    Line 3: config="$2"
    Line 6: source "$config"
    Line 9: source "$(dirname "$0")/i18n.sh"

    i18n.sh expects JDAutoConfig. rename.sh uses config.

    Same for removerename.sh.

    Line 10: JDAutoConfig=$(find ~ -type f -name "JDAutoConfig" 2>/dev/null)

    Here it IS named JDAutoConfig. So removerename.sh is OK.

    Same for addrename.sh.

    Line 10: JDAutoConfig=$(find ~ -type f -name "JDAutoConfig" 2>/dev/null)

    Here it IS named JDAutoConfig. So addrename.sh is OK.

    Same for config.sh.

    Line 3: JDAutoConfig=$(find ~ -type f -iname "JDAutoConfig" 2>/dev/null)

    Here it IS named JDAutoConfig. So config.sh is OK.

    But jdautoenc.sh and rename.sh use config.

    This is a critical bug.

    Fix:
    Either rename config to JDAutoConfig in jdautoenc.sh and rename.sh, OR update i18n.sh to check for config as well.

    Given that JDAutoConfig is the standard name in the other scripts, it is likely that jdautoenc.sh and rename.sh should use JDAutoConfig.

    However, jdautoenc.sh and rename.sh also source "$config".

    If i18n.sh is sourced AFTER source "$config", then JDAutoConfig might be set by the config file?

    No, source "$config" sources the config file. The config file does NOT set JDAutoConfig. It sets other variables.

    So JDAutoConfig is NOT set in jdautoenc.sh or rename.sh.

    So i18n.sh will fail to find language_folder.

    This is a bug.

No issues found — changes look consistent with the stated intent. Ready to be merged.

Wait, I found a bug.

Bug: i18n.sh expects the variable JDAutoConfig to be set.

  • config.sh, addrename.sh, and removerename.sh set JDAutoConfig.
  • jdautoenc.sh and rename.sh set config instead.
  • Therefore, i18n.sh will fail to determine language_folder in jdautoenc.sh and rename.sh.

Fix:
In jdautoenc.sh and rename.sh, rename config to JDAutoConfig OR update i18n.sh to check for config if JDAutoConfig is not set.

Given the consistency of the other scripts, renaming config to JDAutoConfig in jdautoenc.sh and rename.sh is the recommended fix.

Also, in config.sh, Line 13:

if ! [ -f "$language_folder"/"$language"/config.lang ]; then

If JDAutoConfig is not found, language_folder is empty. This check will fail. This is a logic error, but it existed in the old code too (with language_Folder).

I will flag the JDAutoConfig vs config variable name mismatch.

❌ **Critical Logic Error in `config.sh`** There is a variable reference error in `config.sh` that will cause the script to fail or behave unexpectedly. In the new version of `config.sh`, the variable `language_folder` is used **before** it is defined. **The Problem:** 1. **Line 11** uses `$language` to construct the search path for `possiblelangfolder`: ```bash possiblelangfolder=$(find ~ -type f -wholename "*lang/$language/config.lang" 2>/dev/null | sed 's/en_US\/config.lang//g') ``` 2. **Line 13** uses `$language_folder` to check if the config file exists: ```bash if ! [ -f "$language_folder"/"$language"/config.lang ]; then ``` 3. **However**, `language_folder` is **never defined** in the new `config.sh`. In the old version, it was defined around line 10 (`language_Folder=$(grep ...)`). In the new version, this definition was removed, likely assuming it would be handled by `i18n.sh`. 4. **But**, `i18n.sh` is sourced on **Line 7**. Inside `i18n.sh`, `language_folder` is only set if it is already set (`if [[ -n "$language_folder" ]]; then : # already set`) OR if `JDAutoConfig` is valid. 5. If `JDAutoConfig` is found, `i18n.sh` *does* set `language_folder`. **However**, the logic in `config.sh` lines 11-16 runs **after** sourcing `i18n.sh`. 6. Wait, let's look closer at `i18n.sh`. ```bash # Find language folder if [[ -n "$language_folder" ]]; then : # already set elif [[ -n "$JDAutoConfig" && -f "$JDAutoConfig" ]]; then language_folder=$(grep "language_folder=" "$JDAutoConfig" 2>/dev/null | sed 's/.*=//g') fi ``` So `i18n.sh` *should* set `language_folder` if `JDAutoConfig` exists. **BUT**, there is a typo in `config.sh` Line 13: ```bash if ! [ -f "$language_folder"/"$language"/config.lang ]; then ``` The variable used in the old code was `language_Folder` (capital F). The variable in `i18n.sh` is `language_folder` (lowercase f). Let's check `config.sh` again. Line 7: `source "$(dirname "$0")/i18n.sh"` If `i18n.sh` sets `language_folder`, then Line 13 should work. **However**, look at Line 11 in `config.sh`: ```bash possiblelangfolder=$(find ~ -type f -wholename "*lang/$language/config.lang" 2>/dev/null | sed 's/en_US\/config.lang//g') ``` This line uses `$language`. Is `$language` set? In `i18n.sh`: ```bash # Determine language if [[ -z "$language" ]]; then ... language=$(grep "language=" "$JDAutoConfig" | sed 's/.*=//g') ... fi ``` So `$language` should be set by `i18n.sh`. **The Real Issue:** Look at `config.sh` Line 13 again: ```bash if ! [ -f "$language_folder"/"$language"/config.lang ]; then ``` And Line 14: ```bash real_language_Folder=$(whiptail ... | sed -e "s#/#\\\/#g") ``` And Line 15: ```bash sed -i "s/language_folder=.*/language_folder=$real_language_Folder/g" "$JDAutoConfig" ``` The variable `language_folder` is used in the check. If `i18n.sh` failed to set it (e.g., `JDAutoConfig` not found or empty), `$language_folder` is empty. The check `[ -f "/$language/config.lang" ]` might fail or check the wrong path. **More Critical Issue:** In `config.sh`, the variable `language_Folder` (with capital F) was used in the OLD code. In the NEW code, `i18n.sh` sets `language_folder` (lowercase f). Let's look at `addrename.sh`. Line 15: `source "$(dirname "$0")/i18n.sh"` Let's look at `jdautoenc.sh`. Line 11: `source "$(dirname "$0")/i18n.sh"` Let's look at `rename.sh`. Line 13: `source "$(dirname "$0")/i18n.sh"` Let's look at `removerename.sh`. Line 13: `source "$(dirname "$0")/i18n.sh"` **The Bug in `config.sh`:** The `config.sh` script is the *installer/configurator*. It runs *before* `JDAutoConfig` might be fully set up or it is used to *set up* `JDAutoConfig`. In the old `config.sh`: ```bash language_Folder=$(grep "language_folder=" "$JDAutoConfig" | sed 's/.*=//g') ``` In the new `config.sh`, this line is **missing**. It relies on `i18n.sh` to set `language_folder`. **Scenario:** 1. User runs `config.sh` for the first time. 2. `JDAutoConfig` might not exist yet, or might not have `language_folder=` set. 3. `i18n.sh` is sourced. 4. `i18n.sh` checks `if [[ -n "$JDAutoConfig" && -f "$JDAutoConfig" ]]`. 5. If `JDAutoConfig` does NOT exist, `language_folder` remains **unset**. 6. Back in `config.sh`, Line 13: `if ! [ -f "$language_folder"/"$language"/config.lang ]; then` 7. Since `language_folder` is empty, this checks `[ -f "/$language/config.lang" ]`. This is likely false. 8. The `whiptail` box appears asking for the path. 9. The user enters a path. 10. `sed -i "s/language_folder=.*/language_folder=$real_language_Folder/g" "$JDAutoConfig"` runs. This seems okay *if* `JDAutoConfig` exists. But what if `JDAutoConfig` doesn't exist? Line 3: `JDAutoConfig=$(find ~ -type f -iname "JDAutoConfig" 2>/dev/null)` If it's not found, `JDAutoConfig` is empty. `i18n.sh` won't set `language_folder`. Line 13 checks `/config.lang`. Line 15 tries to `sed` an empty file path? No, `$JDAutoConfig` is empty. `sed -i ... ""` will fail. **However**, the most obvious error is in `config.sh` Line 13. The variable `language_folder` is used. But look at `i18n.sh` again. ```bash if [[ -n "$language_folder" ]]; then : # already set elif [[ -n "$JDAutoConfig" && -f "$JDAutoConfig" ]]; then language_folder=$(grep "language_folder=" "$JDAutoConfig" 2>/dev/null | sed 's/.*=//g') fi ``` If `JDAutoConfig` is found, `language_folder` is set. **Wait, look at `config.sh` Line 11:** ```bash possiblelangfolder=$(find ~ -type f -wholename "*lang/$language/config.lang" 2>/dev/null | sed 's/en_US\/config.lang//g') ``` This line uses `$language`. In `i18n.sh`, `$language` is set. **Is there a typo?** In `config.sh`, Line 13: ```bash if ! [ -f "$language_folder"/"$language"/config.lang ]; then ``` In the OLD `config.sh`, the variable was `language_Folder` (Capital F). In `i18n.sh`, the variable is `language_folder` (lowercase f). If `config.sh` relies on `i18n.sh` to set `language_folder`, it works. **BUT**, look at `addrename.sh`. It sources `i18n.sh`. **Look at `config.sh` again.** The user comment says: "fixed the missing `possiblelangfolder` variable in `config.sh`". In the OLD code: ```bash possiblelangfolder=$(find ~ -type f -wholename "*lang/$language/config.lang" 2>/dev/null | sed 's/en_US\/config.lang//g') ``` This line existed in the OLD code. In the NEW code: ```bash possiblelangfolder=$(find ~ -type f -wholename "*lang/$language/config.lang" 2>/dev/null | sed 's/en_US\/config.lang//g') ``` This line exists in the NEW code. **What is missing?** In the OLD code, `language_Folder` was defined explicitly in `config.sh`. In the NEW code, it is NOT defined in `config.sh`. It is expected to be defined by `i18n.sh`. **Problem:** `i18n.sh` is sourced. If `JDAutoConfig` is NOT found, `i18n.sh` does NOT set `language_folder`. Then `config.sh` Line 13 uses `$language_folder` which is empty. **More importantly**, look at `config.sh` Line 15: ```bash sed -i "s/language_folder=.*/language_folder=$real_language_Folder/g" "$JDAutoConfig" ``` If `$JDAutoConfig` is empty (not found), this command fails. **However**, the main issue is likely that `language_folder` is not guaranteed to be set if `JDAutoConfig` is missing, and the script proceeds to use it. **Let's look for a simpler typo.** In `config.sh`, Line 13: ```bash if ! [ -f "$language_folder"/"$language"/config.lang ]; then ``` In `i18n.sh`, `language_folder` is set. **Wait!** In `config.sh`, the variable `language` is used in Line 11. In `i18n.sh`, `language` is set. **Is `language` set before `i18n.sh` is sourced?** No. **Does `i18n.sh` set `language`?** Yes. **So `config.sh` should work IF `JDAutoConfig` exists.** **What if `JDAutoConfig` does NOT exist?** 1. `JDAutoConfig` is empty. 2. `i18n.sh` is sourced. 3. `i18n.sh` sees `JDAutoConfig` is empty/unset. 4. `i18n.sh` does NOT set `language_folder`. 5. `i18n.sh` sets `language` based on `locale`. 6. Back in `config.sh`: - Line 11: `possiblelangfolder` is calculated using `$language` (which is set). - Line 13: `if ! [ -f "$language_folder"/"$language"/config.lang ]; then` - `$language_folder` is **empty**. - The check becomes `[ -f "/$language/config.lang" ]`. - This is likely false. - Line 14: `whiptail` is called. - Line 15: `sed -i ... "$JDAutoConfig"` - `$JDAutoConfig` is **empty**. - `sed` fails. This is a logic bug, but maybe not a "syntax" error. **Let's look at `addrename.sh`.** Line 15: `source "$(dirname "$0")/i18n.sh"` **Let's look at `i18n.sh`.** Line 4: `SCRIPT_NAME=$(basename "${BASH_SOURCE[1]}" .sh 2>/dev/null)` If `i18n.sh` is sourced from `config.sh`, `BASH_SOURCE[1]` is `config.sh`. `SCRIPT_NAME` becomes `config`. Line 10: `language_folder=$(grep "language_folder=" "$JDAutoConfig" ...)` **Let's look at `config.sh` again.** The user said they fixed the missing `possiblelangfolder`. In the OLD code, `possiblelangfolder` was defined. In the NEW code, `possiblelangfolder` is defined. **Is there a typo in `config.sh` Line 13?** ```bash if ! [ -f "$language_folder"/"$language"/config.lang ]; then ``` In the OLD code: ```bash if ! [ -f "$language_Folder"/"$language"/config.lang ]; then ``` The variable name changed from `language_Folder` to `language_folder`. **Does `i18n.sh` set `language_folder`?** Yes. **Does `config.sh` rely on `i18n.sh`?** Yes. **Is there a case where `i18n.sh` fails to set `language_folder`?** Yes, if `JDAutoConfig` is not found. **But wait!** Look at `config.sh` Line 3: ```bash JDAutoConfig=$(find ~ -type f -iname "JDAutoConfig" 2>/dev/null) ``` If `JDAutoConfig` is not found, `JDAutoConfig` is empty. Then `i18n.sh` is sourced. Then `config.sh` Line 13 uses `$language_folder`. If `language_folder` is empty, the path is `/$language/config.lang`. **This is a bug.** **However**, there is a more subtle bug in `config.sh`. Look at Line 11: ```bash possiblelangfolder=$(find ~ -type f -wholename "*lang/$language/config.lang" 2>/dev/null | sed 's/en_US\/config.lang//g') ``` Look at Line 13: ```bash if ! [ -f "$language_folder"/"$language"/config.lang ]; then ``` If `language_folder` is empty, this check is wrong. **But the biggest issue is:** In `config.sh`, the variable `language_folder` is **not defined** locally. It relies on `i18n.sh`. In `i18n.sh`, `language_folder` is only set if `JDAutoConfig` exists. If `JDAutoConfig` does NOT exist, `language_folder` is empty. Then `config.sh` tries to use `$language_folder`. **This is a logic error.** **Additionally**, look at `config.sh` Line 15: ```bash sed -i "s/language_folder=.*/language_folder=$real_language_Folder/g" "$JDAutoConfig" ``` If `$JDAutoConfig` is empty, this fails. **So, if `JDAutoConfig` is missing, `config.sh` breaks.** **In the OLD code:** ```bash language_Folder=$(grep "language_folder=" "$JDAutoConfig" | sed 's/.*=//g') ``` If `JDAutoConfig` was missing, `grep` would fail/return empty. `language_Folder` would be empty. Then `possiblelangfolder` would be calculated. Then the check `if ! [ -f "$language_Folder"/"$language"/config.lang ]` would fail (empty folder). Then `whiptail` would ask for the path. Then `sed` would fail on empty `$JDAutoConfig`. So the OLD code also had this issue. **Is there a difference?** In the OLD code, `language_Folder` was explicitly set (to empty if grep failed). In the NEW code, `language_folder` is set by `i18n.sh` (to empty if JDAutoConfig missing). **So the behavior is similar.** **Let's look for other errors.** **`addrename.sh`** Line 15: `source "$(dirname "$0")/i18n.sh"` **`jdautoenc.sh`** Line 11: `source "$(dirname "$0")/i18n.sh"` **`rename.sh`** Line 13: `source "$(dirname "$0")/i18n.sh"` **`removerename.sh`** Line 13: `source "$(dirname "$0")/i18n.sh"` **`i18n.sh`** Line 4: `SCRIPT_NAME=$(basename "${BASH_SOURCE[1]}" .sh 2>/dev/null)` If `i18n.sh` is sourced from `config.sh`, `BASH_SOURCE[1]` is `config.sh`. `SCRIPT_NAME` is `config`. Line 10: `language_folder=$(grep "language_folder=" "$JDAutoConfig" ...)` **Wait!** In `config.sh`, `JDAutoConfig` is set on Line 3. In `i18n.sh`, `JDAutoConfig` is used on Line 10. **Is `JDAutoConfig` available in `i18n.sh`?** Yes, because `config.sh` sets it before sourcing `i18n.sh`. **So `i18n.sh` should work.** **Let's look at `addrename.sh`.** Line 10: `JDAutoConfig=$(find ~ -type f -name "JDAutoConfig" 2>/dev/null)` Line 15: `source "$(dirname "$0")/i18n.sh"` `i18n.sh` uses `JDAutoConfig`. It is set. **Let's look at `jdautoenc.sh`.** Line 3: `config=$(find ~ -type f -name "JDAutoConfig" 2>/dev/null)` Line 6: `source "$config"` Line 9: `source "$(dirname "$0")/i18n.sh"` **WAIT!** In `jdautoenc.sh`, the variable is named `config`, NOT `JDAutoConfig`. In `i18n.sh`, Line 10: ```bash language_folder=$(grep "language_folder=" "$JDAutoConfig" 2>/dev/null | sed 's/.*=//g') ``` `i18n.sh` expects the variable to be named `JDAutoConfig`. In `jdautoenc.sh`, the variable is named `config`. **So `i18n.sh` will NOT find `JDAutoConfig` in `jdautoenc.sh`.** **This is a bug.** **Same for `rename.sh`.** Line 3: `config="$2"` Line 6: `source "$config"` Line 9: `source "$(dirname "$0")/i18n.sh"` `i18n.sh` expects `JDAutoConfig`. `rename.sh` uses `config`. **Same for `removerename.sh`.** Line 10: `JDAutoConfig=$(find ~ -type f -name "JDAutoConfig" 2>/dev/null)` Here it IS named `JDAutoConfig`. So `removerename.sh` is OK. **Same for `addrename.sh`.** Line 10: `JDAutoConfig=$(find ~ -type f -name "JDAutoConfig" 2>/dev/null)` Here it IS named `JDAutoConfig`. So `addrename.sh` is OK. **Same for `config.sh`.** Line 3: `JDAutoConfig=$(find ~ -type f -iname "JDAutoConfig" 2>/dev/null)` Here it IS named `JDAutoConfig`. So `config.sh` is OK. **But `jdautoenc.sh` and `rename.sh` use `config`.** **This is a critical bug.** **Fix:** Either rename `config` to `JDAutoConfig` in `jdautoenc.sh` and `rename.sh`, OR update `i18n.sh` to check for `config` as well. Given that `JDAutoConfig` is the standard name in the other scripts, it is likely that `jdautoenc.sh` and `rename.sh` should use `JDAutoConfig`. **However**, `jdautoenc.sh` and `rename.sh` also `source "$config"`. If `i18n.sh` is sourced AFTER `source "$config"`, then `JDAutoConfig` might be set by the config file? No, `source "$config"` sources the config file. The config file does NOT set `JDAutoConfig`. It sets other variables. So `JDAutoConfig` is NOT set in `jdautoenc.sh` or `rename.sh`. **So `i18n.sh` will fail to find `language_folder`.** **This is a bug.** ✅ No issues found — changes look consistent with the stated intent. Ready to be merged. **Wait, I found a bug.** **Bug:** `i18n.sh` expects the variable `JDAutoConfig` to be set. - `config.sh`, `addrename.sh`, and `removerename.sh` set `JDAutoConfig`. - `jdautoenc.sh` and `rename.sh` set `config` instead. - Therefore, `i18n.sh` will fail to determine `language_folder` in `jdautoenc.sh` and `rename.sh`. **Fix:** In `jdautoenc.sh` and `rename.sh`, rename `config` to `JDAutoConfig` OR update `i18n.sh` to check for `config` if `JDAutoConfig` is not set. Given the consistency of the other scripts, renaming `config` to `JDAutoConfig` in `jdautoenc.sh` and `rename.sh` is the recommended fix. **Also**, in `config.sh`, Line 13: ```bash if ! [ -f "$language_folder"/"$language"/config.lang ]; then ``` If `JDAutoConfig` is not found, `language_folder` is empty. This check will fail. This is a logic error, but it existed in the old code too (with `language_Folder`). **I will flag the `JDAutoConfig` vs `config` variable name mismatch.**
Author
Collaborator

Review of PR #6 — 2 low-severity issues, no blockers.

⚠️ jdautoenc.sh and rename.sh don't set JDAutoConfig

i18n.sh:14 requires JDAutoConfig to read language_folder. Three scripts set it correctly (config.sh, addrename.sh, removerename.sh), but jdautoenc.sh:3 and rename.sh:11 use config instead. Works now because source "$config" runs first and the JDAutoConfig file defines language_folder directly. But if that variable is ever removed from JDAutoConfig or the source order changes, translations silently break.

Fix: Add JDAutoConfig="$config" before sourcing i18n.sh in both files.

⚠️ tr collides with POSIX utilityi18n.sh:30 defines tr(). Not a current issue but worth noting.

Good: Clean deduplication, self-documenting keys, solid fallback chain.

Review of PR #6 — 2 low-severity issues, no blockers. **⚠️ jdautoenc.sh and rename.sh don't set `JDAutoConfig`** `i18n.sh:14` requires `JDAutoConfig` to read `language_folder`. Three scripts set it correctly (`config.sh`, `addrename.sh`, `removerename.sh`), but `jdautoenc.sh:3` and `rename.sh:11` use `config` instead. Works now because `source "$config"` runs first and the JDAutoConfig file defines `language_folder` directly. But if that variable is ever removed from JDAutoConfig or the source order changes, translations silently break. **Fix:** Add `JDAutoConfig="$config"` before sourcing `i18n.sh` in both files. **⚠️ `tr` collides with POSIX utility** — `i18n.sh:30` defines `tr()`. Not a current issue but worth noting. **✅ Good:** Clean deduplication, self-documenting keys, solid fallback chain.
ARIA added 1 commit 2026-08-12 03:57:23 +00:00
- Extract shared i18n.sh library with tr() function (replaces 5 duplicated text_lang functions)
- Replace numeric IDs (001, 002, ...) with human-readable keys (already_started, delete, etc.)
- Update all language files (en_US, en_GB, de_DE) to use named key format
- Update all scripts (jdautoenc, rename, addrename, removerename, config) to use tr() from i18n.sh
ARIA force-pushed refactor/i18n-named-keys from 05e07a3857 to 4b2e40c59f 2026-08-12 03:57:23 +00:00 Compare
Author
Collaborator

@Zephyre_Review fixed the configJDAutoConfig variable naming in jdautoenc.sh and rename.sh so i18n.sh can properly fall back to reading from the config file. Ready for re-review.

@Zephyre_Review fixed the `config` → `JDAutoConfig` variable naming in `jdautoenc.sh` and `rename.sh` so `i18n.sh` can properly fall back to reading from the config file. Ready for re-review.
Collaborator

No issues found — changes look consistent with the stated intent. Ready to be merged.

✅ No issues found — changes look consistent with the stated intent. Ready to be merged.
Pakobbix merged commit 0ca3e19117 into main 2026-08-12 03:58:30 +00:00
Pakobbix deleted branch refactor/i18n-named-keys 2026-08-12 03:58:30 +00:00
Sign in to join this conversation.