Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
ximper-welcome
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ximper Linux
ximper-welcome
Commits
08dbe113
Commit
08dbe113
authored
Jan 29, 2022
by
Bilal Elmoussaoui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
i18n: use named variables
Fixes #32
parent
451ca975
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
9 deletions
+16
-9
Cargo.lock
Cargo.lock
+1
-0
Cargo.toml
Cargo.toml
+1
-1
utils.rs
src/utils.rs
+10
-7
paginator.rs
src/widgets/paginator.rs
+4
-1
No files found.
Cargo.lock
View file @
08dbe113
...
@@ -328,6 +328,7 @@ dependencies = [
...
@@ -328,6 +328,7 @@ dependencies = [
"libadwaita",
"libadwaita",
"log",
"log",
"pretty_env_logger",
"pretty_env_logger",
"regex",
]
]
[[package]]
[[package]]
...
...
Cargo.toml
View file @
08dbe113
...
@@ -11,4 +11,4 @@ log = "0.4"
...
@@ -11,4 +11,4 @@ log = "0.4"
gettext-rs
=
{
version
=
"0.7"
,
features
=
["gettext-system"]
}
gettext-rs
=
{
version
=
"0.7"
,
features
=
["gettext-system"]
}
adw
=
{package
=
"libadwaita"
,
version
=
"0.1"
}
adw
=
{package
=
"libadwaita"
,
version
=
"0.1"
}
pretty_env_logger
=
"0.4"
pretty_env_logger
=
"0.4"
regex
=
"1.5"
src/utils.rs
View file @
08dbe113
// based on https://gitlab.gnome.org/World/podcasts/-/blob/master/podcasts-gtk/src/i18n|utils.rs
// based on https://gitlab.gnome.org/World/podcasts/-/blob/master/podcasts-gtk/src/i18n|utils.rs
use
gettextrs
::
gettext
;
use
gettextrs
::
gettext
;
use
gtk
::{
gio
,
glib
};
use
gtk
::{
gio
,
glib
};
use
regex
::{
Captures
,
Regex
};
pub
fn
action
<
T
,
F
>
(
thing
:
&
T
,
name
:
&
str
,
action
:
F
)
pub
fn
action
<
T
,
F
>
(
thing
:
&
T
,
name
:
&
str
,
action
:
F
)
where
where
...
@@ -15,12 +16,14 @@ where
...
@@ -15,12 +16,14 @@ where
thing
.add_action
(
&
act
);
thing
.add_action
(
&
act
);
}
}
pub
fn
i18n_f
(
format
:
&
str
,
args
:
&
[
&
str
])
->
String
{
pub
fn
i18n_f
(
format
:
&
str
,
kwargs
:
&
[(
&
str
,
&
str
)])
->
String
{
let
s
=
gettext
(
format
);
let
mut
s
=
gettext
(
format
);
let
mut
parts
=
s
.split
(
"{}"
);
for
(
k
,
v
)
in
kwargs
{
let
mut
output
=
parts
.next
()
.unwrap_or_default
()
.to_string
();
if
let
Ok
(
re
)
=
Regex
::
new
(
&
format!
(
"
\\
{{{}
\\
}}"
,
k
))
{
for
(
p
,
a
)
in
parts
.zip
(
args
.iter
())
{
s
=
re
output
+=
&
(
a
.to_string
()
+
&
p
.to_string
());
.replace_all
(
&
s
,
|
_
:
&
Captures
<
'_
>
|
v
.to_string
())
.to_string
();
}
}
output
}
s
}
}
src/widgets/paginator.rs
View file @
08dbe113
...
@@ -75,7 +75,10 @@ mod imp {
...
@@ -75,7 +75,10 @@ mod imp {
let
name
=
glib
::
os_info
(
"NAME"
)
.unwrap_or_else
(||
"GNOME"
.into
());
let
name
=
glib
::
os_info
(
"NAME"
)
.unwrap_or_else
(||
"GNOME"
.into
());
let
version
=
glib
::
os_info
(
"VERSION"
)
.unwrap_or_else
(||
""
.into
());
let
version
=
glib
::
os_info
(
"VERSION"
)
.unwrap_or_else
(||
""
.into
());
// Translators: The following string is formated as "Learn about new and essential features in GNOME 3.36" for example
// Translators: The following string is formated as "Learn about new and essential features in GNOME 3.36" for example
let
body
=
i18n_f
(
"Learn about the key features in {} {}."
,
&
[
&
name
,
&
version
]);
let
body
=
i18n_f
(
"Learn about the key features in {name} {version}."
,
&
[(
"name"
,
&
name
),
(
"version"
,
&
version
)],
);
let
welcome_page
=
ImagePageWidget
::
new
(
let
welcome_page
=
ImagePageWidget
::
new
(
"/org/gnome/Tour/welcome.svg"
,
"/org/gnome/Tour/welcome.svg"
,
gettext
(
"Start the Tour"
),
gettext
(
"Start the Tour"
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment