-
-
Notifications
You must be signed in to change notification settings - Fork 405
[breaking] legacy: refactoring of the old Logger
(part 2 of 2)
#1625
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
852c91a
legacy: refactored ErrorfWithLogger function
cmaglie a7b69f2
Renamed legacy ctx fields ExecStdout/ExecStderr to Stdout/Stderr
cmaglie 5ed306f
Removed empty Lint() function
cmaglie 01cff69
Removed dependency on i18n.Logger
cmaglie a943802
Removed no more used i18n.Logger \o/ \o/
cmaglie 43b8177
Simplified i18n.Init function
cmaglie 11346e4
legacy: builder default output on os.Stdout/os.Stderr
cmaglie 57b531c
legacy: updated integration tests for slightly different output of bu…
cmaglie 372f290
Use positional parameter for most translated string
cmaglie dd7a195
Added note to UPGRADING.md
cmaglie 0371a8e
Updated UPGRADING.md
cmaglie 3c474ca
Removed extra blank line in library detection recap
cmaglie 7a034de
Update docs/UPGRADING.md
cmaglie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,44 @@ | ||
// This file is part of arduino-cli. | ||
// | ||
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) | ||
// | ||
// This software is released under the GNU General Public License version 3, | ||
// which covers the main part of arduino-cli. | ||
// The terms of this license can be found at: | ||
// https://www.gnu.org/licenses/gpl-3.0.en.html | ||
// | ||
// You can be released from the requirements of the above licenses by purchasing | ||
// a commercial license. Buying such a license is mandatory if you want to | ||
// modify or otherwise use the software for commercial activities involving the | ||
// Arduino software without disclosing the source code of your own applications. | ||
// To purchase a commercial license, send an email to license@arduino.cc. | ||
|
||
package i18n | ||
|
||
import ( | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
var javaFormatPlaceholderRegexp = regexp.MustCompile(`{(\d)}`) | ||
|
||
// FromJavaToGoSyntax convert a translation string made for Java to a one suitable for golang (printf-style). | ||
// The conversion transforms java placeholders like "{0}","{1}","{2}",etc... with the equivalent for golang | ||
// "%[1]v","%[2]v","%[3]v",etc... | ||
// The double single-quote "''" is translated into a single single-quote "'". | ||
func FromJavaToGoSyntax(s string) string { | ||
// Replace "{x}" => "%[x+1]v" | ||
for _, submatch := range javaFormatPlaceholderRegexp.FindAllStringSubmatch(s, -1) { | ||
idx, err := strconv.Atoi(submatch[1]) | ||
if err != nil { | ||
panic(err) | ||
} | ||
s = strings.Replace(s, submatch[0], "%["+strconv.Itoa(idx+1)+"]v", -1) | ||
} | ||
|
||
// Replace "''" => "'" | ||
s = strings.Replace(s, "''", "'", -1) | ||
|
||
return s | ||
} |
This file contains hidden or 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,54 @@ | ||
// This file is part of arduino-cli. | ||
// | ||
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) | ||
// | ||
// This software is released under the GNU General Public License version 3, | ||
// which covers the main part of arduino-cli. | ||
// The terms of this license can be found at: | ||
// https://www.gnu.org/licenses/gpl-3.0.en.html | ||
// | ||
// You can be released from the requirements of the above licenses by purchasing | ||
// a commercial license. Buying such a license is mandatory if you want to | ||
// modify or otherwise use the software for commercial activities involving the | ||
// Arduino software without disclosing the source code of your own applications. | ||
// To purchase a commercial license, send an email to license@arduino.cc. | ||
|
||
package i18n | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func format(format string, a ...interface{}) string { | ||
format = FromJavaToGoSyntax(format) | ||
message := fmt.Sprintf(format, a...) | ||
return message | ||
} | ||
|
||
func TestI18NSyntax(t *testing.T) { | ||
require.Equal(t, "Do you want to remove %[1]v?\nIf you do so you won't be able to use %[1]v any more.", FromJavaToGoSyntax("Do you want to remove {0}?\nIf you do so you won't be able to use {0} any more.")) | ||
require.Equal(t, "A file named \"%[1]v\" already exists in \"%[2]v\"", FromJavaToGoSyntax("A file named \"{0}\" already exists in \"{1}\"")) | ||
require.Equal(t, "Board %[1]v:%[2]v:%[3]v doesn't define a 'build.board' preference. Auto-set to: %[4]v", FromJavaToGoSyntax("Board {0}:{1}:{2} doesn''t define a ''build.board'' preference. Auto-set to: {3}")) | ||
|
||
require.Equal(t, "22 11\n", fmt.Sprintf("%[2]d %[1]d\n", 11, 22)) | ||
require.Equal(t, "d c b a", format("{3} {2} {1} {0}", "a", "b", "c", "d")) | ||
|
||
require.Equal(t, "e d b a", format("{4} {3} {1} {0}", "a", "b", "c", "d", "e")) | ||
|
||
require.Equal(t, "a b", format("{0} {1}", "a", "b", "c", "d", "e")) | ||
|
||
require.Equal(t, "%!v(BADINDEX) c b a", format("{3} {2} {1} {0}", "a", "b", "c")) | ||
require.Equal(t, "%!v(BADINDEX) %!v(BADINDEX) %!v(BADINDEX) %!v(BADINDEX)", format("{3} {2} {1} {0}")) | ||
|
||
require.Equal(t, "I'm %[1]v%% sure", FromJavaToGoSyntax("I'm {0}%% sure")) | ||
require.Equal(t, "I'm 100% sure", format("I'm {0}%% sure", 100)) | ||
|
||
require.Equal(t, "Either in [1] or in [2]", format("Either in [{0}] or in [{1}]", 1, 2)) | ||
|
||
require.Equal(t, "Using library a at version b in folder: c ", format("Using library {0} at version {1} in folder: {2} {3}", "a", "b", "c", "")) | ||
|
||
require.Equal(t, "Missing 'a' from library in b", format("Missing '{0}' from library in {1}", "a", "b")) | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.