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

More documentation and traits for Locale #8

Merged
merged 5 commits into from
Jan 26, 2024
Merged
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
65 changes: 61 additions & 4 deletions generate-api/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,29 +491,86 @@ impl CodeGenerator {
f,
r#"

/// Locales matching the locales in `glibc`.
///
/// Most locale names follow the syntax `language[_territory][@modifier]`.
/// The `@` is replaced with `_` in the `enum` variant names.
///
/// The default locale is `POSIX`.
///
/// License note: The Free Software Foundation does not claim any copyright interest in the locale
/// data of the GNU C Library; they believe it is not copyrightable.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This license note seems quite out of place 😄.
When a someone browses the documentation of an MIT-licensed library and then seeds "glibc" and "GNU" I expect this will be a question.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's great to show that we have done our due diligence on this.

Here are the emails I exchanged with them from back in the days:

Subject: Re: [gnu.org #1488572] Question about GLIBC and data files
Date: 25 Feb 2020, 07:34
From: Ineiev via RT [email protected]

Hello, and thank you for writing in!

I asked first a lawyer this question but he couldn't give me an answer so I
thought maybe it would be easier to ask you directly.

I recently made a small open-source library which helps to internationalize.
https://github.com/cecton/pure-rust-locales

However, to do this I used the data files (not the source code) (these are
files that contain information on languages) from another library: glibc. glibc
is licensed under LGPLv2.1 and I have a doubt tha
t I am doing something legal.

At the head of each data file it is written:

% This file is part of the GNU C Library and contains locale data.
% The Free Software Foundation does not claim any copyright interest
% in the locale data contained in this file. The foregoing does not
% affect the license of the GNU C Library as a whole. It does not
% exempt you from the conditions of the license if your use would
% otherwise be governed by that license.

I really can't read lawyer language so I don't know if my lib is usable by
anyone. For example: can someone use my lib in proprietary software? It's a bit
blocking and it's a shame because it would help s
everal other open source projects.

For example I would like to contribute there but this is stuck because of this
legal question: chronotope/chrono#199

In short, we believe these files aren't copyrightable; for more background,
please check https://sourceware.org/ml/libc-locales/2013-q1/msg00048.html

--
I am not a lawyer, this is not a legal advice.

The services of the GPL Compliance Lab are made possible by
donations from people like you. Please consider supporting us
today by becoming a member [https://my.fsf.org/join] or by making
a donation [https://www.fsf.org/donate].
q1/msg00048.html

--
I am not a lawyer, this is not a legal advice.

The services of the GPL Compliance Lab are made possible by
donations from people like you. Please consider supporting us
today by becoming a member [https://my.fsf.org/join] or by making
a donation [https://www.fsf.org/donate].

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good to see the complete context, chronotope/chrono#453 (comment) had the important bit of it 👍.

#[allow(non_camel_case_types,dead_code)]
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Copy, Clone, Default, PartialEq, Eq, Hash)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I always wonder what's "default" on an enum like that ^_^ it's like, the first entry in the enum? If that's the case, I'm not sure this is a good idea. Do we really need a default on something like this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, that is tricky.

According to https://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap07.html#tag_07_02:

For C-language programs, the POSIX locale shall be the default locale when the setlocale() function is not called.

In chrono I added a default_locale() function: https://github.com/chronotope/chrono/blob/0.4.x/src/format/locales.rs#L5 to return POSIX.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would be happy with posix

pub enum Locale {{
"#,
)?;
f.indent(1);

for (lang, norm) in self.normalized_langs.iter() {
let desc = match self
.by_language
.get(lang)
.and_then(|l| l.get("LC_IDENTIFICATION"))
{
Some(Category::Fields(fields)) => match fields.get("TITLE") {
Some(Value::Literal(title)) => {
let mut title = title.clone();
if !title.ends_with('.') {
title.push('.');
}
title
}
_ => match lang == "POSIX" {
true => "POSIX Standard Locale.".to_string(),
false => "".to_string(),
},
},
_ => "".to_string(),
};
write!(f, "\n/// `{}`: {}\n", lang, desc)?;
if lang == &"POSIX" {
writeln!(f, "\n#[default]\n")?;
}
Comment on lines +532 to +534
Copy link
Collaborator

Choose a reason for hiding this comment

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

ahh that's the default

writeln!(f, "\n{},\n", norm)?;
}

f.dedent(1);
write!(
f,
r#"
}}

impl core::fmt::Display for Locale {{
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {{
f.write_str(match self {{
"#,
)?;
f.indent(3);

for (lang, norm) in self.normalized_langs.iter() {
write!(
f,
r#"
/// {lang}
{norm},
Locale::{norm} => {lang:?},
"#,
lang = lang,
norm = norm,
)?;
}

f.dedent(1);
f.dedent(3);
write!(
f,
r#"
}})
}}
}}

impl core::fmt::Debug for Locale {{
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {{
core::fmt::Display::fmt(self, f)
}}
}}

impl core::str::FromStr for Locale {{
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Git LFS file not shown
Loading