Init commit

This commit is contained in:
Markus Scully 2024-11-14 20:56:28 +00:00
commit 3a9f283e99
No known key found for this signature in database
GPG key ID: B8470B38660AF9E8
13 changed files with 418 additions and 0 deletions

3
.envrc Normal file
View file

@ -0,0 +1,3 @@
source_url "https://raw.githubusercontent.com/cachix/devenv/95f329d49a8a5289d31e0982652f7058a189bfca/direnvrc" "sha256-d+8cBpDfDBj41inrADaJt+bDWhOktwslgoP5YiGJ1v0="
use devenv

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
/target
.devenv*
devenv.local.nix
.pre-commit-config.yaml

54
Cargo.lock generated Normal file
View file

@ -0,0 +1,54 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "autolingual"
version = "0.1.0"
dependencies = [
"autolingual-macro",
]
[[package]]
name = "autolingual-macro"
version = "0.1.0"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "proc-macro2"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
dependencies = [
"proc-macro2",
]
[[package]]
name = "syn"
version = "2.0.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"

6
Cargo.toml Normal file
View file

@ -0,0 +1,6 @@
[workspace]
members = [
"autolingual",
"autolingual-macro"
]
resolver = "2"

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Markus Scully
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

25
README.md Normal file
View file

@ -0,0 +1,25 @@
# Autolingual
Procedural macros in Rust can execute arbitrary code at compile time, even performing network requests. This has potentially terrifying security implications, but we'll use it to our advantage!
Autolingual is a Rust macro which automatically translates strings of natural language text into multiple foreign languages at once at compile time. The produced translations are `&'static str` values, so they are very lightweight.
## Examples
```rs
use autolingual::{translate, TranslationSet};
// No context
let button_text_french: &str = translate!("Sign up").fr;
// With context (context will not show up in the final translation)
let button_text_french: &str = translate!("Sign up", "A button for creating a user account.").fr;
// Every supported language at once.
let translation_set: TranslationSet = translate!("Hello!");
let french = translation_set.fr;
let german = translation_set.de;
let portuguese = translation_set.pt;
// ...
```

View file

@ -0,0 +1,14 @@
[package]
name = "autolingual-macro"
version = "0.1.0"
edition = "2021"
license = "MIT"
description = "Procedural macros for autolingual"
[lib]
proc-macro = true
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "2.0", features = ["full"] }

View file

@ -0,0 +1,18 @@
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, LitStr};
#[proc_macro]
pub fn translate(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as LitStr);
let text = input.value();
// TODO: Implement actual translation logic
quote! {
::autolingual::TranslationSet {
en: #text,
fr: "TODO",
}
}.into()
}

9
autolingual/Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "autolingual"
version = "0.1.0"
edition = "2021"
license = "MIT"
description = "Compile-time natural language translations using translation APIs"
[dependencies]
autolingual-macro = { path = "../autolingual-macro", version = "0.1.0" }

12
autolingual/src/lib.rs Normal file
View file

@ -0,0 +1,12 @@
pub use autolingual_macro::translate;
pub struct Language {
pub code: &'static str,
pub name: &'static str,
}
#[derive(Debug)]
pub struct TranslationSet {
pub en: &'static str,
pub fr: &'static str,
}

178
devenv.lock Normal file
View file

@ -0,0 +1,178 @@
{
"nodes": {
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1731619804,
"owner": "cachix",
"repo": "devenv",
"rev": "87edaaf1dddf17fe16eabab3c8edaf7cca2c3bc2",
"treeHash": "c0c2fd8edf08b32c9da79d4bb917690dc5b126d0",
"type": "github"
},
"original": {
"dir": "src/modules",
"owner": "cachix",
"repo": "devenv",
"type": "github"
}
},
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1731565929,
"owner": "nix-community",
"repo": "fenix",
"rev": "4c6c7d5088f12f57afd4ba6449f9eb168ca05620",
"treeHash": "06a361535bdfec44eb64eb02dc5628ea71b2f488",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"treeHash": "2addb7b71a20a25ea74feeaf5c2f6a6b30898ecb",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"treeHash": "ca14199cabdfe1a06a7b1654c76ed49100a689f9",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1716977621,
"owner": "cachix",
"repo": "devenv-nixpkgs",
"rev": "4267e705586473d3e5c8d50299e71503f16a6fb6",
"treeHash": "6d9f1f7ca0faf1bc2eeb397c78a49623260d3412",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "rolling",
"repo": "devenv-nixpkgs",
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1731386116,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "689fed12a013f56d4c4d3f612489634267d86529",
"treeHash": "8786ed18f037bad8b80b7a75c0e7b21a6769ee87",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-unstable": {
"locked": {
"lastModified": 1731531548,
"owner": "nixos",
"repo": "nixpkgs",
"rev": "24f0d4acd634792badd6470134c387a3b039dace",
"treeHash": "a35f71a0fa18e0a51dfeead7b9c971ed73043752",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1731363552,
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "cd1af27aa85026ac759d5d3fccf650abe7e1bbf0",
"treeHash": "d246c8c2f312332367d56063d2b049419880acc7",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"devenv": "devenv",
"fenix": "fenix",
"nixpkgs": "nixpkgs",
"nixpkgs-unstable": "nixpkgs-unstable",
"pre-commit-hooks": "pre-commit-hooks"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1731342671,
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "fc98e0657abf3ce07eed513e38274c89bbb2f8ad",
"treeHash": "7c4a6b17fbe9e655cac7d03a3c034456b8f60a1f",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

60
devenv.nix Normal file
View file

@ -0,0 +1,60 @@
{
pkgs,
lib,
config,
inputs,
...
}:
let
pkgs-unstable = import inputs.nixpkgs-unstable {
system = pkgs.stdenv.system;
config.allowUnfree = true;
};
in
{
# https://devenv.sh/basics/
env.GREET = "devenv";
# https://devenv.sh/packages/
packages = [
pkgs-unstable.git
pkgs-unstable.rustup
pkgs-unstable.code-cursor
pkgs-unstable.curl
pkgs-unstable.jq
];
# https://devenv.sh/languages/
languages.rust = {
channel = "nightly";
components = [
"cargo"
"rust-src"
"rustc"
"clippy"
];
enable = true;
};
enterShell = ''
rustup component add clippy
'';
enterTest = ''
echo "Running tests"
git --version | grep --color=auto "${pkgs.git.version}"
cargo clippy -- -D warnings
'';
pre-commit.hooks = {
shellcheck.enable = true;
clippy = {
enable = true;
name = "clippy";
entry = "cargo clippy -- -D warnings";
files = "\\.rs$";
language = "system";
};
};
}

14
devenv.yaml Normal file
View file

@ -0,0 +1,14 @@
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
inputs:
fenix:
url: github:nix-community/fenix
inputs:
nixpkgs:
follows: nixpkgs
nixpkgs:
url: github:cachix/devenv-nixpkgs/rolling
nixpkgs-unstable:
url: github:nixos/nixpkgs/nixpkgs-unstable
allowUnfree: true