-
Notifications
You must be signed in to change notification settings - Fork 26
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
Unicode to English literals #7
Open
Uuttssaavv
wants to merge
17
commits into
sarbagyastha:develop
Choose a base branch
from
Uuttssaavv:unicode_to_english
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b128e93
conversion for devnagari alphabets, vowels and numbers
Uuttssaavv a98d2c4
added conversion of special symbols
Uuttssaavv dc7823d
added test cases for Nepali to English literals conversion and vice-v…
Uuttssaavv 9cd31ed
added exmple conversion from Unicode to English literals
Uuttssaavv b3d5d1c
updated README.md
Uuttssaavv c29d558
added trailing comma
Uuttssaavv 040668f
changed from var(s) to final(s)
Uuttssaavv 964d4db
changed from splittedString to characters
Uuttssaavv 92506c6
made maps constant instead of getters
Uuttssaavv 652b67b
added missing trailing comma
Uuttssaavv 7ac59ff
renamed fullStr to character
Uuttssaavv 15451a5
extracted convertedString[i - 1] as preecedingCharacter
Uuttssaavv ad346b1
added comment for symbol check
Uuttssaavv c5cbf08
returned directly
Uuttssaavv 2efd67d
formatted
Uuttssaavv 82618e8
added comment
Uuttssaavv 2310cce
used the value of preceeding character to convertedString[i-1] and it…
Uuttssaavv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Copyright 2020 Sarbagya Dhaubanjar. All rights reserved. | ||
// Use of this source code is governed by a MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
/// Converts Nepali Unicode (Devnagari Literals) into English(Roman) literals. | ||
class UnicodeToEnglish { | ||
/// Converts specifies [text] into english literals. | ||
/// | ||
/// if live is true, texts will convert in live manner. | ||
/// i.e. as you go on typing | ||
/// Default for live is false. | ||
static String convert(String text, {bool live = false}) { | ||
final characters = text.split(''); | ||
final convertedString = <String>[]; | ||
for (var i = 0; i < characters.length; i++) { | ||
if (i < characters.length - 1 && characters[i + 1] == '\u094D') { | ||
var character = _unicodeMap[characters[i]].toString(); | ||
character = character.substring(0, character.length - 1); | ||
convertedString.add(character); | ||
} else if (characters[i] != '\u094D') { | ||
convertedString.add( | ||
_unicodeMap[characters[i]] ?? characters[i], | ||
); | ||
} | ||
} | ||
for (var i = 0; i < convertedString.length; i++) { | ||
// if the converted string contains symbols | ||
if (_symbolMap[convertedString[i]] != null) { | ||
var preecedingCharacter = convertedString[i - 1].toString(); | ||
print('$preecedingCharacter ${preecedingCharacter.endsWith('a')}'); | ||
// eg. tha + ु (u) = thu | ||
if (preecedingCharacter.endsWith('a')) { | ||
preecedingCharacter = | ||
preecedingCharacter.substring(0, preecedingCharacter.length - 1); | ||
Comment on lines
+33
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this used ? |
||
convertedString[i - 1] = preecedingCharacter; | ||
} | ||
|
||
convertedString[i] = _symbolMap[convertedString[i]] ?? ''; | ||
} | ||
} | ||
return convertedString.join(''); | ||
} | ||
} | ||
|
||
const Map<String, String> _unicodeMap = { | ||
//ka - gya | ||
'\u0915': 'ka', | ||
'\u0916': 'kha', | ||
'\u0917': 'ga', | ||
'\u0918': 'gha', | ||
'\u0919': 'ng', | ||
'\u091A': 'ca', | ||
'\u091B': 'cha', | ||
'\u091C': 'ja', | ||
'\u091D': 'jha', | ||
'\u091E': 'ya', | ||
'\u091F': 'Ta', | ||
'\u0920': 'Tha', | ||
'\u0921': 'Da', | ||
'\u0922': 'Dha', | ||
'\u0923': 'na', | ||
'\u0924': 'ta', | ||
'\u0925': 'tha', | ||
'\u0926': 'da', | ||
'\u0927': 'dha', | ||
'\u0928': 'na', | ||
'\u092A': 'pa', | ||
'\u092B': 'fa', | ||
'\u092C': 'ba', | ||
'\u092D': 'bha', | ||
'\u092E': 'ma', | ||
'\u092F': 'ya', | ||
'\u0930': 'ra', | ||
'\u0932': 'la', | ||
'\u0935': 'wa', | ||
'\u0936': 'sha', | ||
'\u0937': 'sha', | ||
'\u0938': 'sa', | ||
'\u0939': 'ha', | ||
'\u0915\u094D\u0937': 'xa', | ||
'\u0924\u094D\u0930': 'tra', | ||
'\u091C\u094D\u091E': 'gya', | ||
// a - ahm | ||
'\u0905': 'a', | ||
'\u0906': 'aa', | ||
'\u0907': 'i', | ||
'\u0908': 'ii', | ||
'\u0909': 'u', | ||
'\u090A': 'oo', | ||
'\u090F': 'e', | ||
'\u0910': 'ai', | ||
'\u0913': 'o', | ||
'\u0914': 'au', | ||
'\u0935\u0902': 'am', | ||
'\u0935\u0903': 'ah', | ||
|
||
//numbers | ||
'\u0966': '0', | ||
'\u0967': '1', | ||
'\u0968': '2', | ||
'\u0969': '3', | ||
'\u096a': '4', | ||
'\u096b': '5', | ||
'\u096c': '6', | ||
'\u096d': '7', | ||
'\u096e': '8', | ||
'\u096f': '9', | ||
//symbols | ||
'%2c': ',', | ||
}; | ||
const Map<String, String> _symbolMap = { | ||
'\u093E': 'aa', | ||
'\u093F': 'i', | ||
'\u0940': 'ii', | ||
'\u0941': 'u', | ||
'\u0942': 'U', | ||
'\u0947': 'e', | ||
'\u0948': 'ai', | ||
'\u094B': 'o', | ||
'\u094C': 'au', | ||
|
||
'\u0901': "''", //chandrabindu | ||
'\u0902': "'", //shreebindu | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import 'package:nepali_utils/nepali_utils.dart'; | ||
import 'package:nepali_utils/src/unicode_to_english.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
|
@@ -164,6 +165,25 @@ void main() { | |
), | ||
); | ||
}); | ||
group('text converter ', () { | ||
final englishText = | ||
"ka baaTa kachuwaa kha kharaayo\nkharaayoko sing' chaina kataa haraayo"; | ||
final nepaliText = 'क बाट कछुवा ख खरायो\nखरायोको सिङं छैन कता हरायो'; | ||
test( | ||
'conversion of english to nepali unicode', | ||
() => expect( | ||
NepaliUnicode.convert('$englishText'), | ||
'$nepaliText', | ||
), | ||
); | ||
test( | ||
'conversion of nepali to english unicode', | ||
() => expect( | ||
UnicodeToEnglish.convert('$nepaliText'), | ||
'$englishText', | ||
), | ||
); | ||
}); | ||
Comment on lines
+168
to
+186
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests do not belong in this file. |
||
} | ||
|
||
String _format(number) => NepaliNumberFormat().format(number); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct ?