Skip to content

Commit

Permalink
Feature/Linux support (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgzonArifi authored Jan 15, 2024
1 parent fbb6d9c commit 1fef320
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ You can download the macOS app from [App Store](https://apps.apple.com/us/app/li
- **Settings Configuration:** Easily configure and manage your settings through the app's settings panel.
- **Translation Initiation:** Initiate the translation process with a single click without the need for terminal commands.

### 2. Terminal App
### 2. macOS Terminal App

For those who prefer using the terminal or require scriptable solutions, Lingua offers a terminal app that allows you to manage and initiate translations directly from the command line.

Expand All @@ -107,7 +107,27 @@ $ brew tap poviolabs/lingua
$ brew install lingua
```

#### Configuration file
### 3. Linux Terminal App

Lingua runs on Linux as well.

#### Installation

1. Download the latest release `Lingua_Linux` from [GitHub Releases](https://github.com/poviolabs/Lingua/releases) based on your machine, either `Lingua_Linux_x86_64` or `Lingua_Linux_arm64`

2. Make the binary executable:

```shell
$ chmod +x /path/to/Lingua_Linux_x86_64
$ mv Lingua_Linux lingua
$ sudo mv /path/to/lingua /usr/local/bin
```

### Terminal Usage

Please follow below instructions to use Lingua in terminal.

##### Configuration file

Create a configuration file as a starting point to adapt as your needs, `lingua_config.json` or any other `.json` file.

Expand All @@ -125,15 +145,15 @@ Then in the configuration file created you need to provide your data, like below
}
```

#### Output directory
##### Output directory

The output directory property should be the path where you want the tool to create localization files.

* For iOS it can be any directory on your project. After you run the command, for the first time, you have to **`Add files to 'YourProject'`** in Xcode.

* For Android, since the translation are placed in a specific project directory, the output directory it should look something like this: **`path/YourProject/app/src/main/res `**

#### iOS specific
##### iOS specific

Since iOS does not have a built in feature to access the localization safely, we have made this possible using Lingua tool. In the configuration file you have to provide the path where the default language strings are stored and where the Swift file you want to be created. With that the tool will create **Lingua.swift** with an enumeration to easily access localizations in your app.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

protocol HTTPClient {
func fetchData(with request: URLRequest) async throws -> (Data, HTTPURLResponse)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

class URLSessionHTTPClient: HTTPClient {
private let urlSession: URLSession
Expand All @@ -8,11 +11,33 @@ class URLSessionHTTPClient: HTTPClient {
}

func fetchData(with request: URLRequest) async throws -> (Data, HTTPURLResponse) {
#if canImport(FoundationNetworking)
return try await makeData(for: request)
#else
let (data, response) = try await urlSession.data(for: request)
guard let httpResponse = response as? HTTPURLResponse else {
throw InvalidHTTPResponseError(statusCode: 0, data: data)
}

return (data, httpResponse)
#endif
}
}

private extension URLSessionHTTPClient {
func makeData(for request: URLRequest) async throws -> (Data, HTTPURLResponse) {
try await withCheckedThrowingContinuation { continuation in
let task = urlSession.dataTask(with: request) { data, response, error in
if let error = error {
continuation.resume(throwing: error)
return
}
guard let data = data, let httpResponse = response as? HTTPURLResponse else {
continuation.resume(throwing: URLError(.badServerResponse))
return
}
continuation.resume(returning: (data, httpResponse))
}
task.resume()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

final class APIRequestExecutor {
private let requestBuilder: URLRequestBuilder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

struct URLRequestBuilder {
let baseURLString: String
Expand Down

0 comments on commit 1fef320

Please sign in to comment.