Skip to content

Commit

Permalink
Remove tag: prefix on tag translate
Browse files Browse the repository at this point in the history
  • Loading branch information
violet-dev committed Aug 25, 2024
1 parent 97d2e21 commit 7ca23dd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
26 changes: 17 additions & 9 deletions violet/lib/component/hitomi/tag_translate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,22 @@ class TagTranslate {
return null;
}

if (translateMap.containsKey(key)) {
late final String nomalizedKey;
if (key.startsWith('tag:female:') || key.startsWith('tag:male:')) {
nomalizedKey = key.substring('tag:'.length);
} else {
nomalizedKey = key;
}

if (translateMap.containsKey(nomalizedKey)) {
return null;
}

translateMap[key] = value;
reverseAndroMap[disassembly(value)
.replaceAll('female:', '')
.replaceAll('male:', '')] = key;
late final String nomalizedValue =
value.replaceAll('female:', '').replaceAll('male:', '');

translateMap[nomalizedKey] = nomalizedValue;
reverseAndroMap[disassembly(nomalizedValue)] = nomalizedKey;

return null;
},
Expand Down Expand Up @@ -87,11 +95,11 @@ class TagTranslate {
if (_translateMap.containsKey('character:$key')) {
return _translateMap['character:$key']!.split('|').first;
}
if (_translateMap.containsKey('tag:female:$key')) {
return _translateMap['tag:female:$key']!.split('|').first;
if (_translateMap.containsKey('female:$key')) {
return _translateMap['female:$key']!.split('|').first;
}
if (_translateMap.containsKey('tag:male:$key')) {
return _translateMap['tag:male:$key']!.split('|').first;
if (_translateMap.containsKey('male:$key')) {
return _translateMap['male:$key']!.split('|').first;
}
if (_translateMap.containsKey('tag:$key')) {
return _translateMap['tag:$key']!.split('|').first;
Expand Down
19 changes: 19 additions & 0 deletions violet/test/translate_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This source code is a part of Project Violet.
// Copyright (C) 2020-2024. violet-team. Licensed under the Apache-2.0 License.

import 'package:flutter_test/flutter_test.dart';
import 'package:violet/component/hitomi/tag_translate.dart';

void main() {
group('Query Test', () {
setUp(() async {
await TagTranslate.init();
});

test('Translate Korean Simple', () {
expect(TagTranslate.ofAny('sole female'), '단독여성');
expect(TagTranslate.ofAny('pokemon'), '포켓몬');
expect(TagTranslate.ofAny('teitoku'), '제독');
});
});
}

0 comments on commit 7ca23dd

Please sign in to comment.