-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Konstantinos Bairaktaris
committed
Oct 20, 2022
1 parent
a6b056f
commit 9b0b42a
Showing
3 changed files
with
73 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import itertools | ||
import re | ||
|
||
from fluent.syntax import ast, parse | ||
from openformats.strings import OpenString | ||
from openformats.transcribers import Transcriber | ||
from openformats.utils.compilers import OrderedCompilerMixin | ||
|
||
from ..handlers import Handler | ||
|
||
|
||
class FluentHandler(OrderedCompilerMixin, Handler): | ||
name = "FLUENT" | ||
extension = "ftl" | ||
EXTRACTS_RAW = True | ||
|
||
def parse(self, source, is_source=False): | ||
transcriber = Transcriber(source) | ||
source = transcriber.source | ||
parsed = parse(source) | ||
stringset = [] | ||
order = itertools.count() | ||
for item in parsed.body: | ||
if not isinstance(item, (ast.Message, ast.Term)): | ||
continue | ||
key = item.id.name | ||
value = source[item.value.span.start : item.value.span.end] | ||
string = OpenString(key, value, order=next(order)) | ||
stringset.append(string) | ||
transcriber.copy_until(item.value.span.start) | ||
transcriber.add(string.template_replacement) | ||
transcriber.skip(item.value.span.end - item.value.span.start) | ||
transcriber.copy_to_end() | ||
return transcriber.get_destination(), stringset | ||
|
||
@staticmethod | ||
def unescape(string: str): | ||
lines = string.splitlines() | ||
if len(lines) > 1: | ||
indent = re.search("^s*", lines[1]).end() | ||
result = [lines[0].strip()] | ||
for line in lines[1:]: | ||
if not line[:indent].isspace(): | ||
return string | ||
result.append(line[indent:].strip()) | ||
return " ".join(lines) | ||
else: | ||
return string | ||
|
||
@staticmethod | ||
def escape(string): | ||
return string |
Empty file.
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,21 @@ | ||
## Closing tabs | ||
|
||
tabs-close-button = Close | ||
tabs-close-tooltip = {$tabCount -> | ||
[one] Close {$tabCount} tab | ||
*[other] Close {$tabCount} tabs | ||
} | ||
tabs-close-warning = | ||
You are about to close {$tabCount} tabs. | ||
Are you sure you want to continue? | ||
## Syncing | ||
|
||
-sync-brand-name = Firefox Account | ||
sync-dialog-title = {-sync-brand-name} | ||
sync-headline-title = | ||
{-sync-brand-name}: The best way to bring | ||
your data always with you | ||
sync-signedout-title = | ||
Connect with your {-sync-brand-name} |