Skip to content

Commit

Permalink
feat: add first version
Browse files Browse the repository at this point in the history
  • Loading branch information
euskadi31 committed Feb 24, 2022
0 parents commit da58258
Show file tree
Hide file tree
Showing 14 changed files with 655 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
root = true

[*]
charset = utf-8
end_of_line = LF
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab

[*.md]
trim_trailing_whitespace = false

[*.go]
indent_style = tab

[*.yml]
indent_size = 2

[*.yaml]
indent_size = 2

[*.yml.dist]
indent_size = 2
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
time: "04:00"
open-pull-requests-limit: 10
assignees:
- euskadi31
151 changes: 151 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
name: Go

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.17
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build
run: go build -race -v ./...

- name: Test
run: go test -race -cover -coverprofile ./coverage.out ./...

- name: Coverage
id: coverage
run: |
go tool cover -func ./coverage.out | tee -a coverage.txt
echo "COVERAGE_CONTENT<<EOF" >> $GITHUB_ENV
cat coverage.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- uses: actions/github-script@v4
if: github.event_name == 'pull_request'
env:
COVERAGE_CONTENT: "${{ env.COVERAGE_CONTENT }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `Code Coverage\n
\`\`\`\n
${process.env.COVERAGE_CONTENT}
\`\`\`
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`;
const response = await github.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
var comments = response.data;
console.log(comments);
if (comments.length > 0) {
comments = comments.filter(comment => comment.body.includes('Code Coverage') && comment.user.type === 'Bot');
}
if (comments.length > 0) {
const comment = comments.shift();
github.issues.updateComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
body: output
})
} else {
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}
- name: Benchmark
id: benchmark
run: |
go test -benchmem -bench . | tee -a benchmark.txt
echo "BENCHMARK_CONTENT<<EOF" >> $GITHUB_ENV
cat benchmark.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- uses: actions/github-script@v4
if: github.event_name == 'pull_request'
env:
BENCHMARK_CONTENT: "${{ env.BENCHMARK_CONTENT }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `Benchmark\n
\`\`\`\n
${process.env.BENCHMARK_CONTENT}
\`\`\`
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`;
const response = await github.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
var comments = response.data;
console.log(comments);
if (comments.length > 0) {
comments = comments.filter(comment => comment.body.includes('Benchmark') && comment.user.type === 'Bot');
}
if (comments.length > 0) {
const comment = comments.shift();
github.issues.updateComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
body: output
})
} else {
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.41.1
skip-pkg-cache: true

- name: Coveralls
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
*.out

vendor/

*.swp
95 changes: 95 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
run:
concurrency: 4
deadline: 1m
issues-exit-code: 1
tests: false
skip-files:
- ".*_mock\\.go"
- "mock_.*\\.go"
- ".*/pkg/mod/.*$"

output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true

linters-settings:
errcheck:
check-type-assertions: false
check-blank: false
govet:
check-shadowing: false
revive:
ignore-generated-header: true
severity: warning
gofmt:
simplify: true
gocyclo:
min-complexity: 18
maligned:
suggest-new: true
dupl:
threshold: 80
goconst:
min-len: 4
min-occurrences: 3
depguard:
list-type: blacklist
include-go-root: false
packages:
- github.com/davecgh/go-spew/spew
misspell:
locale: US
ignore-words:
- cancelled
goimports:
local-prefixes: go.opentelemetry.io


linters:
disable-all: true
enable:
- deadcode
- depguard
- errcheck
- gas
- goconst
- gocyclo
- gofmt
- revive
- govet
- ineffassign
- megacheck
- misspell
- structcheck
- typecheck
- unconvert
- varcheck
- gosimple
- staticcheck
- unused
- asciicheck
- bodyclose
- dogsled
- dupl
- durationcheck
- errorlint
- exhaustive
- exportloopref
- forbidigo
- forcetypeassert
- gocritic
- godot
- gosec
- ifshort
- nestif
- nilerr
- nlreturn
- noctx
- prealloc
- predeclared
- sqlclosecheck
- tagliatelle
- whitespace
- wsl
fast: false
19 changes: 19 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2022 Axel Etcheverry

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.
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.PHONY: all clean test cover travis lint

release:
@echo "Release v$(version)"
@git pull
@git checkout master
@git pull
@git checkout develop
@git flow release start $(version)
@git flow release finish $(version) -p -m "Release v$(version)"
@git checkout develop
@echo "Release v$(version) finished."

all: test

clean:
@go clean -i ./...

coverage.out: $(shell find . -type f -print | grep -v vendor | grep "\.go")
@go test -race -cover -coverprofile ./coverage.out.tmp ./...
@cat ./coverage.out.tmp | grep -v '.pb.go' | grep -v 'mock_' > ./coverage.out
@rm ./coverage.out.tmp

test: coverage.out

lint:
@golangci-lint run

cover: coverage.out
@echo ""
@go tool cover -func ./coverage.out

50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Hyperscale Translation [![Last release](https://img.shields.io/github/release/hyperscale-stack/translation.svg)](https://github.com/hyperscale-stack/translation/releases/latest) [![Documentation](https://godoc.org/github.com/hyperscale-stack/translation?status.svg)](https://godoc.org/github.com/hyperscale-stack/translation)

[![Go Report Card](https://goreportcard.com/badge/github.com/hyperscale-stack/translation)](https://goreportcard.com/report/github.com/hyperscale-stack/translation)

| Branch | Status | Coverage |
| ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| master | [![Build Status](https://github.com/hyperscale-stack/translation/workflows/Go/badge.svg?branch=master)](https://github.com/hyperscale-stack/translation/actions?query=workflow%3AGo) | [![Coveralls](https://img.shields.io/coveralls/hyperscale-stack/translation/master.svg)](https://coveralls.io/github/hyperscale-stack/translation?branch=master) |

The Hyperscale translation library provides a simple translation manager over `x/text` package.

## Example

```go
package main

import (
"fmt"

"github.com/hyperscale-stack/locale"
"github.com/hyperscale-stack/translation"
"golang.org/x/text/language"
"golang.org/x/text/message/catalog"
)

func main() {
c := catalog.NewBuilder(catalog.Fallback(language.English))
c.SetString(language.English, "Hello World", "Hello World")
c.SetString(language.French, "Hello World", "Bonjour le monde")

// the default language is always language.English, for override use translation.WithDefaultLocale()
trans := translation.New(
[]language.Tag{
language.English,
language.French,
},
translation.WithCatalog(c),
)

ctx := context.Background()

ctx = locale.ToContext(ctx, language.French)

trans.Translate(ctx, "Hello World") // return Bonjour le monde
}

```

## License

Hyperscale Translation is licensed under [the MIT license](LICENSE.md).
Loading

0 comments on commit da58258

Please sign in to comment.