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

[Feature] Added ignore translation list #8

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ void main(List<String> arguments) {
"sayau' thu''gaa fUlakaa haamii, euTai maalaa nepaalii"));
print(NepaliUnicode.convert(
'saarwabhauma bhai failiekaa, mecii-mahaakaalii\n'));

heading('Nepali Unicode with number');
print(NepaliUnicode.convert('10000.10'));

heading('Nepali Unicode with number and ignore list');
print(NepaliUnicode.convert('10,000.10', ignoreList: ['.']));
}

void heading(String text) {
Expand Down
22 changes: 18 additions & 4 deletions lib/src/nepali_unicode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,39 @@
/// Converts English literal (Roman Literals) into Nepali Unicode.
class NepaliUnicode {
static String _text = '';
static List<String> _ignoreList = [];

/// Converts specifies [text] into nepali 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}) {
/// if ignoreList is provided, text in list will not be translated
static String convert(
String text, {
bool live = false,
List<String> ignoreList = const [],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of using a Regex instead ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's an good idea. let me make the neccessary changes

}) {
_ignoreList = ignoreList;
if (live) {
return _unicode(text);
return _convert(text);
}
_text = '';
for (var index = 0; index < text.length; index++) {
final char = text[index];
if (index == 0) {
_text = _unicode(text[0]);
_text = _convert(char);
} else {
_text = _unicode(_text + text[index]);
_text = _unicode(_text + char);
}
}
return _text;
}

static String _convert(String data) {
return _ignoreList.contains(data) ? data : _unicode(data);
}

static String _unicode(String data) {
_text = data;
_replace('a', '\u0905');
Expand Down Expand Up @@ -195,10 +207,12 @@ class NepaliUnicode {
}

static void _replace(x, y) {
if (_ignoreList.contains(x)) return;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed ?

_text = _text.replaceAll(x, String.fromCharCodes(Runes(y)));
}

static void _replaceRunes(x, y) {
if (_ignoreList.contains(x)) return;
_text = _text.replaceAll(
String.fromCharCodes(Runes(x)),
String.fromCharCodes(Runes(y)),
Expand Down