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

Updated uppercase letters for latin languages #2794

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Telsho
Copy link

@Telsho Telsho commented Dec 21, 2024

Hello,

I solved the problem of uppercase letters for latin languages (issue #2502), I updated the uppercase letters for these keys:

  • 'weekdays',
    
  • 'weekdaysShort',
    
  • 'weekdaysMin',
    
  • 'months',
    
  • 'monthsShort'
    

This is the script I used to change the uppercase letters:

import os
import re

# List of non-Latin script languages to skip
NON_LATIN_LANGUAGES = {
    'ar', 'ar-dz', 'ar-iq', 'ar-kw', 'ar-ly', 'ar-ma', 'ar-sa', 'ar-tn',
    'bn', 'bn-bd', 'bo', 'dv', 'fa', 'gu', 'he', 'hi', 'ja', 'ka', 'kn',
    'ko', 'ml', 'mr', 'my', 'ne', 'si', 'ta', 'te', 'th', 'uk', 'zh',
    'zh-cn', 'zh-hk', 'zh-tw', 'sr-cyrl'
}

# Properties to capitalize
PROPS_TO_CAPITALIZE = [
    'weekdays',
    'weekdaysShort',
    'weekdaysMin',
    'months',
    'monthsShort'
]

def should_process_file(filename: str) -> bool:
    """Determine if the file should be processed based on language code."""
    base_lang = filename.split('.')[0].split('-')[0]
    return base_lang not in NON_LATIN_LANGUAGES

def capitalize_string(s: str) -> str:
    """Capitalize the first character of a string."""
    return s[0].upper() + s[1:] if s else s

def process_file(file_path: str) -> bool:
    """Process a single file and capitalize relevant strings."""
    try:
        with open(file_path, 'r', encoding='utf-8') as file:
            content = file.read()

        modified_content = content
        changes_made = False

        for prop in PROPS_TO_CAPITALIZE:
            # Match the property and its array content
            pattern = f"{prop}:\\s*['\"](.*?)['\"]\\s*\\.split\\(['\"]\\_['\"]\\)"
            matches = re.finditer(pattern, modified_content)

            for match in matches:
                original_string = match.group(0)
                values = match.group(1).split('_')
                capitalized_values = [capitalize_string(val) for val in values]
                new_string = f"{prop}: '{'_'.join(capitalized_values)}'.split('_')"

                if new_string != original_string:
                    modified_content = modified_content.replace(original_string, new_string)
                    changes_made = True

        if changes_made:
            with open(file_path, 'w', encoding='utf-8') as file:
                file.write(modified_content)
            print(f"Updated {file_path}")
            return True
        else:
            print(f"No changes needed for {file_path}")
            return False

    except Exception as e:
        print(f"Error processing {file_path}: {str(e)}")
        return False

def main():
    """Main function to process all JS files in the current directory."""
    directory = '.'  # Current directory
    js_files = [f for f in os.listdir(directory) if f.endswith('.js')]
    
    processed_count = 0
    skipped_count = 0
    updated_count = 0

    for file in js_files:
        file_path = os.path.join(directory, file)
        
        if should_process_file(file):
            if process_file(file_path):
                updated_count += 1
            processed_count += 1
        else:
            print(f"Skipping non-Latin script file: {file}")
            skipped_count += 1

    print("\nProcessing complete:")
    print(f"- Files processed: {processed_count}")
    print(f"- Files updated: {updated_count}")
    print(f"- Files skipped: {skipped_count}")

if __name__ == '__main__':
    main()

Let me know if you want me to change something else, or maybe change the scope of languages converted.

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.

1 participant