-
Notifications
You must be signed in to change notification settings - Fork 64
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
Automatically choose preposition-article contraction in Portuguese #294
Open
1ec5
wants to merge
2
commits into
master
Choose a base branch
from
1ec5-pt-grammar
base: master
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
2 commits
Select commit
Hold shift + click to select a range
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,31 @@ | ||
{ | ||
"abbreviations": { | ||
"quadra": "Qd", | ||
"vila": "Vil" | ||
}, | ||
"classifications": { | ||
"avenida": "Av", | ||
"caminho": "Cam", | ||
"estrada": "Estr", | ||
"rua": "R", | ||
"travessa": "Tv" | ||
}, | ||
"directions": { | ||
"lés-nordeste": "ENE", | ||
"nordeste": "NE", | ||
"oeste": "O", | ||
"sudeste": "SE", | ||
"lés-sudeste": "ESE", | ||
"nor-nordeste": "NNE", | ||
"sul": "S", | ||
"nor-noroeste": "NNO", | ||
"noroeste": "NO", | ||
"norte": "N", | ||
"oés-sudoeste": "OSO", | ||
"oés-noroeste": "ONO", | ||
"sudoeste": "SO", | ||
"sul-sudeste": "SSE", | ||
"su-sudoeste": "SSO", | ||
"leste": "L" | ||
} | ||
} |
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,48 @@ | ||
{ | ||
"meta": { | ||
"regExpFlags": "gi" | ||
}, | ||
"v5": { | ||
"em": [ | ||
["^ A(s?) ", " na$1 "], | ||
["^ O(s?) ", " no$1 "], | ||
|
||
["^ (Marginal|Parte|Passagem|Ponte|Radial|Rede|Servid[aã]o) ", " na $1 "], | ||
["^ (Anel|Bosque|Boulevard|Cais|Canal|Caracol|Casal|Catete|Coronel|Duque|Fim|General|Impasse|Jardim|Juiz|Lote|Marechal|Mirante|Oriente|Parque|Professor|Setor|Tenente|Terminal|T[uú]nel) ", " no $1 "], | ||
|
||
["^ ([^\\- ]+dade)(s?) ", " na$2 $1$2 "], | ||
["^ ([^\\- ]+z) ", " na $1 "], | ||
["^ ([^\\- ]+z)es ", " nas $1es "], | ||
["^ ([^\\- ]+[cçz][aã]o) ", " na $1 "], | ||
["^ ([^\\- ]+[cçz][oõ]es) ", " nas $1 "], | ||
|
||
["^ ([^\\- ]+dor) ", " no $1 "], | ||
["^ ([^\\- ]+dor)es ", " nos $1es "], | ||
|
||
["^ (?!n[ao]s? )([^\\- ]+)([ao]s?) ", " n$2 $1$2 "], | ||
|
||
["^ (?!n[ao]s? )(\\S)", " em $1"] | ||
], | ||
"a": [ | ||
["^ A(s?) ", " à$1 "], | ||
["^ O(s?) ", " ao$1 "], | ||
|
||
["^ (Marginal|Parte|Passagem|Ponte|Radial|Rede|Servid[aã]o) ", " à $1 "], | ||
["^ (Anel|Bosque|Boulevard|Cais|Canal|Caracol|Casal|Catete|Coronel|Duque|Fim|General|Impasse|Jardim|Juiz|Lote|Marechal|Mirante|Oriente|Parque|Professor|Setor|Tenente|Terminal|T[uú]nel) ", " ao $1 "], | ||
|
||
["^ ([^\\- ]+dade)(s?) ", " à$2 $1$2 "], | ||
["^ ([^\\- ]+z) ", " à $1 "], | ||
["^ ([^\\- ]+z)es ", " às $1es "], | ||
["^ ([^\\- ]+[cçz][aã]o) ", " à $1 "], | ||
["^ ([^\\- ]+[cçz][oõ]es) ", " às $1 "], | ||
|
||
["^ ([^\\- ]+dor) ", " ao $1 "], | ||
["^ ([^\\- ]+dor)es ", " aos $1es "], | ||
|
||
["^ ([^\\- ]+)a(s?) ", " à$2 $1a$2 "], | ||
["^ (?!aos? )([^\\- ]+)o(s?) ", " ao$2 $1o$2 "], | ||
|
||
["^ (?!aos? |às? )(\\S)", " a $1"] | ||
] | ||
} | ||
} |
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,34 @@ | ||
// Add grammar option to {way_name} depending on phrase context | ||
|
||
var replaces = [ | ||
[' (n[ao] +)?\{(destination|junction_name|way_name|waypoint_name)\}', ' {$1:em}'], // eslint-disable-line no-useless-escape | ||
[' (ao +|à +)?\{(destination|junction_name|way_name|waypoint_name)\}', ' {$1:a}'] // eslint-disable-line no-useless-escape | ||
]; | ||
|
||
function optionize(phrase) { | ||
var result = phrase; | ||
replaces.forEach(function(pattern) { | ||
var re = new RegExp(pattern[0], 'gi'); | ||
result = result.replace(re, pattern[1]); | ||
}); | ||
|
||
return result; | ||
} | ||
|
||
function iterate(values) { | ||
Object.keys(values).forEach(function (key) { | ||
var value = values[key]; | ||
if (typeof value === 'string') { | ||
values[key] = optionize(value); | ||
} else if (typeof value === 'object') { | ||
iterate(value); | ||
} | ||
}); | ||
} | ||
|
||
module.exports = function(content) { | ||
// Iterate all content string values recursively | ||
iterate(content.v5); | ||
|
||
return content; | ||
}; |
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
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.
And maybe also item for "generic" Portuguese
'pt': abbreviationsPt,
?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.
This PR copies the abbreviations object to two keys for consistency with the translation files, but the client is expected to perform some sort of locale matching. Even if we were to set
pt
, the environment’s locale may be something else likept-AO
or evenpt-US
. There are plenty of libraries that can perform locale matching, such as locale-utils.I’m not necessarily opposed to setting the language-only locale, but I think we’d want to do so consistently for all languages and resource types, and I’m not sure that would be feasible for a situation like
zh
.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.
Actually I don't see the problem with this grammar use for all Portuguese dialects - grammar expressions will match only Portuguese street names even if
pt-US
will be used in US with English names. Or there is a difference in Portuguese articles usage inpt-BR
andpt-US
?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.
Right, I think abbreviations and grammar rules should be available regardless of the specific Portuguese locale in use, but it should be up to the client to choose a country to default to. For now the two locales share the same abbreviations and grammar rules, but that wouldn’t necessarily be the case in the future for all languages, so I’d be hesitant to create an expectation that clients can look up grammars without performing locale matching first, which they have to do when getting a translated instruction.
If it’s a major inconvenience for clients to perform locale matching themselves, then we could have this library depend on locale-utils, but there are larger libraries with more robust locale matching and I wouldn’t want to force clients to use the more rudimentary logic in locale-utils.