kargnas / laravel-ai-translator

Automatic translate your language files into many languages using AI like Claude, GPT and etc.
MIT License
79 stars 8 forks source link

Unit tests? #2

Open mgralikowski opened 1 month ago

mgralikowski commented 1 month ago

The AI's result is unpredictable, so it's a bit tricky to build unit tests, but what do you think about adding some, based on very basic words to test the most important aspects (preserving pluralization, variables, capitalization)? It could be similar to the examples I attached in my PR.

kargnas commented 1 month ago

I think we absolutely need the Unit test, but I don't have time to write it, and I'm not used to writing test code.

This is what I'm using personally for testing purposes. I hope someone can implement unit tests.

<?php

return [
    'updated_at_short' => 'Updated at :time',

    // 문장으로 번역하면 안됨
    'box_title_read_in_other_languages' => 'Read in other languages which are translated by AI',

    // 기본적인 단수/복수형
    'apple' => 'There is one apple|There are many apples',

    // 복잡한 복수형 규칙
    'orange' => '{0} There are no oranges|{1} There is one orange|[2,4] There are a few oranges|[5,*] There are many oranges',

    // 동사 형태 (원형, 진행형, 과거분사)
    'verb_forms' => [
        'infinitive' => 'to run',
        'present_participle' => 'running',
        'past_participle' => 'run',
    ],

    // UI 요소 (버튼, 레이블 등)
    'ui' => [
        'btn_submit' => 'Submit',
        'btn_cancel' => 'Cancel',
        'label_username' => 'Username:',
        'placeholder_password' => 'Enter your password',
    ],

    // 변수를 포함한 복수형
    'minute_ago' => '{1} :value minute ago|[2,*] :value minutes ago',

    // 내장 :count 플레이스홀더 사용
    'stars' => '{0} There are no stars|{1} There is one star|[2,*] There are :count stars',

    // 복잡한 문장 구조 (현재형과 과거형)
    'welcome_message' => [
        'present' => 'Welcome to our application, :name! You have :count unread message|Welcome to our application, :name! You have :count unread messages',
        'past' => 'You were welcomed to our application, :name! You had :count unread message|You were welcomed to our application, :name! You had :count unread messages',
    ],

    // HTML 태그를 포함한 번역
    'bold_text' => 'This is <b>bold</b> text with a {0} variable|This is <b>bold</b> text with :count variables',

    // 특수 문자와 이스케이프 처리
    'special_chars' => "Don't forget to use the \"pipe\" character: |",

    // 중첩된 배열 구조 (다양한 형태 포함)
    'nested' => [
        'level1' => [
            'level2' => 'This is a nested translation',
            'plural' => 'One item|Many items',
            'verb' => [
                'infinitive' => 'to nest',
                'present' => 'nests',
                'past' => 'nested',
            ],
        ],
    ],

    // 긴 텍스트 번역 (다양한 시제 포함)
    'long_text' => [
        'present' => "This is a very long text that spans
            multiple lines. It's important to test
            how the translator handles this kind of content.

            New paragraph here.",
        'past' => "This was a very long text that spanned
            multiple lines. It was important to test
            how the translator handled this kind of content.

            New paragraph was here.",
    ],

    // 복잡한 복수형과 변수를 결합
    'complex_plural' => '{0} No results of type :type|{1} One result of type :type|[2,*] :count results of type :type',

    // 번역하지 않아야 할 기술 용어
    'tech_terms' => 'Use the `artisan` command to manage your Laravel application',

    // 컨텍스트가 필요한 번역
    'bank' => 'I went to the bank|The river bank was muddy',

    // 지역화가 필요한 날짜 표현
    'season' => "It's :season now",

    // 관용구 (직역하면 안 되는 표현)
    'idioms' => [
        'raining_cats_dogs' => "It's raining cats and dogs",
        'piece_of_cake' => 'The task was a piece of cake',
    ],

    // 약어와 두문자어
    'abbreviations' => [
        'asap' => 'Please complete this ASAP',
        'fyi' => 'FYI: The meeting is at 3 PM',
    ],

    'person_count_cap' => '1 Person|:count People',
    'person_count' => '1 person|:count people',
    'ball_count' => ':count ball|:count balls',

    // Basic singular and plural
    'book_simple' => 'There is one book|There are :count books',

    // Complex pluralization with specific numbers
    'book_complex' => '{0} There are no books|{1} There is one book|{2} There are two books|[3,10] There are :count books|[11,*] There are :count books',

    // Mix of singular, dual and plural in one sentence
    'book_distribution' => 'I have one book, Ahmed has two books, and the library has :count books',
];